﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using Smallerp.Services;
using System.Reflection;
using SmallERP.Host.Frm;
using SmallERP.HostBll.BaseInfo;
using Leadtools.SpecialEffects;

using Leadtools;
using System.Threading;
using SmallERP.MODEL;
using System.IO;
using SmallERP.Bll.MakeBigPic;
using Leadtools.Codecs;
using SmallERP.MODEL.MakeBigPic;
using System.Collections;
using SmallERP.COM;
using Leadtools.ImageProcessing.Effects;
using Leadtools.ColorConversion;
using Microsoft.Win32;
//using VectorPointDll;
using SmallERP.HostBll.MakeBigPic;
using SmallERP.HostBll.Com;
using System.ServiceProcess;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using Leadtools.ImageProcessing;
using SmallERP.MODEL.PrintManage;
using WHDXF;

namespace SmallERP.Host
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
            // MessageBox.Show("11");
            try
            {

                shopService = new ServiceHost(typeof(OperateDBServer)); //数据库操作服务
                FenPianService = new ServiceHost(typeof(OperateDBFenPian));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            dlUplbl = UPTLab;
            dlUpProgress = UPTPgro;


            SetSize();
            SetLocation();
            SetTimer();
            // MessageBox.Show("13");
            _mainBLL = new MainBLL(Properties.Settings.Default.ServerIP, Properties.Settings.Default.ServerPort);
            // MessageBox.Show("14");
            //this.cmbPicType.SelectedIndex = 1;//默认生成JPG
            gFont = this.CreateGraphics();

            SizeF sizeF = gFont.MeasureString("30000000000", textBarFont13);
            BARCODEWIDTH = ((int)sizeF.Width) + 10;//条码的宽度

            // MessageBox.Show("15");
        }
        ~FrmMain()
        {
            RasterCodecs.Shutdown();
        }
        ServiceHost shopService = null;
        ServiceHost FenPianService = null;

        //SmallERP.MakeBigPic.FrmMain frmMake;
        SysSet setBll = new SysSet();

        private string SavePicPath = string.Empty;//渲染大图的零时文件夹

        const int COLORBLOCKWIDTH = 50;//色块的宽度
        const int BLOCKSEPARATION = 5;//各块之间的间距多少

        private static float FontSize = 20f;//条码字体的大小
        private bool FontIsBold = false;//字体是否加粗

        private int ProductPicCount = 0;//总共生成了多少张大图
        private int PicFormat = 0;//0代表jpg,1代表TIFF
        private bool _isMore = false;//详细信息
        private int BARCODEWIDTH;//条码的宽度，根据字体的大小得到其像素大小
        private int BARCODEHEIDHT = 30;//条码的高度大约2mm
        private Font textBarFont3o9 = new Font("3 of 9 Barcode", 8);//条码的信息
        private Font textBarFont3o92 = new Font("3 of 9 Barcode", 8);//条码的信息
        //private Font textFont = new Font("华文中宋", FontSize);//文字的字体
        private Font textFont = new Font("Arial", FontSize);//文字的字体
        private Font textBarFont13 = new Font("Code EAN13", 65);//条码的信息
        //private Font textBarFont = new Font("EAN-13", 75);//条码的信息
        public string _printName = string.Empty;
        public bool IsReboot = false;
        string doubleQM = "\"";
        private XmlOperator _xmlOp = new XmlOperator();
        private MainBLL _mainBLL;
        private DelegateUPTLab dlUplbl;//用于更新LABEL的委托
        private DelegateUPTPgro dlUpProgress;//用于更新进度条的委托
        private Graphics gFont;
        private const string CONNERR = "与服务器连接异常，请检查与服务器的网络连接";
        string strTempPath = Application.StartupPath + "\\abc.jpg";//如果是用PS加载ICC时，是用来临时存放到本地的大图的路径
        MarkImageDll.ClassInterface mai = null;


        PSApplition psApp = null;

        //LayoutDll.ClassInterFace InterFace = null;
        //private bool IsPrintLine = true;
        //private bool IsAutoCut = true;
        //private int SelectBarCodeType = 0;
        //private double MinPhotoRemarkLength = 0;

        //private string PhotoRemarkOrder = "";
        //private int CutMinPhotoNum = 0;
        //private int PhotoRemarkFlag = 0;//照片区分标志0双色块，1为底色
        //private int TextAlignType = 0;
        //private int SaveFileType = 0;
        //private List<int> WaitClearFolderBoardID = new List<int>();
        //private int BoardLineWidth = 1;

        List<RasterColor> listColor = new List<RasterColor>();//颜色列表
        List<BoardModel> ListError = new List<BoardModel>();//错误版面列表
        private int MainFormWidth = 624;
        private int MainFormSamllHeight = 160;
        private int MainFormBigHeight = 435;
        private string CurrCutPath;
        private RasterSizeFlags PictureQuality = RasterSizeFlags.Bicubic;
        private int RemarkInPicBottomOrTop = 0;
        private int RemarkInPicRightOrLeft = 0;
        private int MerginMMCen = 0;
        private int MerginMMWH = 0;
        private void Form1_Load(object sender, EventArgs e)
        {
            IniFile.FilePath = Application.StartupPath;
            //spinEdit1.Text = IniFileOper.IniReadValue("Host", "FontSize");
            //this.Text = "惟鸿ERP自动合成，当前服务IP:" + DateTransfer.LocalIPadress;

            toolStripStatusLabel2.Text = "服务IP地址:" + DateTransfer.LocalIPadress;
            System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController();
            sc.ServiceName = "NetTcpPortSharing";
            if (sc.Status != ServiceControllerStatus.Running)
            {
                sc.Start();
            }
            SetLocation();
            //MessageBox.Show("1");
            RasterCodecs.Startup();
            //MessageBox.Show("2");
            try
            {
                shopService.Open();
                FenPianService.Open();
            
                // MessageBox.Show("3");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            try
            {
                psApp = new PSApplition();
                //InterFace = new LayoutDll.ClassInterFace();
            }
            catch
            {
                MessageBox.Show("PS启动失败请安装PS!");
            }
            try
            {
                mai = new MarkImageDll.ClassInterface();
            }
            catch
            {
                MessageBox.Show("插件MarkImageDll初始化失败!");
            }
            try
            {
                // iccLoad = new IccDll.ClassInterface();
            }
            catch
            {
                MessageBox.Show("插件IccDll初始化失败!");
            }

            //try
            //{
            //    UDPMessage.SendMessage();
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.ToString());
            //}
            //frmMake = new SmallERP.MakeBigPic.FrmMain();
            //lbHistoryData.Text = Properties.Settings.Default.HistoryDataSaveDays.ToString();
            //Properties.Settings.Default.

            //显示当前的配置信息
            SavePicPath = SystemSettingBLL.GetProductPicPath();
            if (string.IsNullOrEmpty(SavePicPath))
            {
                MessageBox.Show("没有设定渲染大图的临时文件夹,请先设定!");
                this.Close();
            }
            IniFile.FilePath = Application.StartupPath;
            //SetFontInfo();
            InitPara();
            // DateTransfer.IsPrintBarCodeInPicture = true;//测试打印在照片上
            #region//颜色列表
            listColor.Add(new RasterColor(0, 0, 0));
            listColor.Add(new RasterColor(150, 150, 150));
            listColor.Add(new RasterColor(130, 0, 20));
            listColor.Add(new RasterColor(242, 24, 38));
            listColor.Add(new RasterColor(255, 242, 5));
            listColor.Add(new RasterColor(28, 128, 79));
            listColor.Add(new RasterColor(0, 163, 231));

            listColor.Add(new RasterColor(63, 70, 209));
            listColor.Add(new RasterColor(255, 90, 255));
            listColor.Add(new RasterColor(255, 255, 255));
            listColor.Add(new RasterColor(200, 160, 255));
            listColor.Add(new RasterColor(184, 127, 84));
            listColor.Add(new RasterColor(254, 170, 202));
            listColor.Add(new RasterColor(254, 200, 0));
            listColor.Add(new RasterColor(240, 228, 173));
            listColor.Add(new RasterColor(177, 231, 30));
            listColor.Add(new RasterColor(154, 217, 233));
            listColor.Add(new RasterColor(111, 147, 191));
            listColor.Add(new RasterColor(202, 189, 243));
            listColor.Add(new RasterColor(128, 0, 60));
            listColor.Add(new RasterColor(79, 81, 81));

            listColor.Add(new RasterColor(0, 127, 0));
            listColor.Add(new RasterColor(0, 255, 0));
            listColor.Add(new RasterColor(255, 0, 127));
            listColor.Add(new RasterColor(160, 71, 196));
            listColor.Add(new RasterColor(128, 128, 0));
            listColor.Add(new RasterColor(0, 64, 127));
            listColor.Add(new RasterColor(127, 254, 254));
            listColor.Add(new RasterColor(128, 0, 128));
            listColor.Add(new RasterColor(255, 0, 255));
            #endregion

            Thread thMake = new Thread(StratWork);
            thMake.IsBackground = true;
            thMake.Start();
        }
        //设置窗体的位置
        private void SetLocation()
        {
            Rectangle rect = Screen.PrimaryScreen.WorkingArea;
            this.Location = new Point(rect.Width - this.Width, rect.Height - this.Height);
        }
        /// <summary>
        /// 初始化各种参数
        /// </summary>
        void InitPara()
        {
            string IsPrintLineStr = IniFile.IniReadValue("Host", "IsPrintLine");
            if (string.IsNullOrEmpty(IsPrintLineStr))
            {

                IniFile.IniWriteValue("Host", "IsPrintLine", "True");
                DateTransfer.IsPrintLine = Convert.ToBoolean(IniFile.IniReadValue("Host", "IsPrintLine"));

            }
            else
            {
                DateTransfer.IsPrintLine = Convert.ToBoolean(IsPrintLineStr);

            }
            string IsAutoCutStr = IniFile.IniReadValue("Host", "IsAutoCut");
            if (string.IsNullOrEmpty(IsAutoCutStr))
            {
                IniFile.IniWriteValue("Host", "IsAutoCut", "False");
                DateTransfer.IsAutoCut = Convert.ToBoolean(IniFile.IniReadValue("Host", "IsAutoCut"));

            }
            else
            {
                DateTransfer.IsAutoCut = Convert.ToBoolean(IsAutoCutStr);

            }
            string BarCodeSizeStr = IniFile.IniReadValue("Host", "BarCodeSize");
            if (string.IsNullOrEmpty(BarCodeSizeStr))
            {
                IniFile.IniWriteValue("Host", "BarCodeSize", "32");

            }

            int codeBar = Convert.ToInt16(IniFile.IniReadValue("Host", "BarCodeSize"));
            string MinPhotoRemarkLengthStr = IniFile.IniReadValue("Host", "MinPhotoRemarkLength");
            if (string.IsNullOrEmpty(MinPhotoRemarkLengthStr))
            {
                IniFile.IniWriteValue("Host", "MinPhotoRemarkLength", "3");
            }
            DateTransfer.MinPhotoRemarkLength = Convert.ToDouble(IniFile.IniReadValue("Host", "MinPhotoRemarkLength"));

            textBarFont13 = new Font("Code EAN13", codeBar);//条码的信息
            textBarFont3o9 = new Font("C39HrP48DmTt", codeBar);//条码的信息
            textBarFont3o92 = new Font("C39HrP48DmTt", codeBar);
            string TextFontSizeStr = IniFile.IniReadValue("Host", "TextFontSize");
            if (string.IsNullOrEmpty(TextFontSizeStr))
            {
                IniFile.IniWriteValue("Host", "TextFontSize", "8");

            }
            DateTransfer.TextFontSize = Convert.ToInt16(IniFile.IniReadValue("Host", "TextFontSize"));
            string TextFontStr = IniFile.IniReadValue("Host", "TextFont");
            if (string.IsNullOrEmpty(TextFontStr))
            {
                IniFile.IniWriteValue("Host", "TextFont", "Arial");

            }
            TextFontStr = IniFile.IniReadValue("Host", "TextFont");
            if (string.IsNullOrEmpty(TextFontStr))
            {

                textFont = new Font("Arial", DateTransfer.TextFontSize);
                DateTransfer.TextFont = "Arial";
            }
            else
            {
                DateTransfer.TextFont = TextFontStr;
                textFont = new Font(DateTransfer.TextFont, DateTransfer.TextFontSize);
            }
            string PrintRemarkOrderStr = IniFile.IniReadValue("Host", "PrintRemarkOrder");
            if (string.IsNullOrEmpty(PrintRemarkOrderStr))
            {
                IniFile.IniWriteValue("Host", "PrintRemarkOrder", "123");
                DateTransfer.PhotoRemarkOrder = IniFile.IniReadValue("Host", "PrintRemarkOrder");
            }
            else
            {
                DateTransfer.PhotoRemarkOrder = PrintRemarkOrderStr;

            }

            string CutMinPhotoNumStr = IniFile.IniReadValue("Host", "CutMinPhotoNum");
            if (string.IsNullOrEmpty(CutMinPhotoNumStr))
            {
                IniFile.IniWriteValue("Host", "CutMinPhotoNum", "1");

                DateTransfer.CutMinPhotoNum = Convert.ToInt16(IniFile.IniReadValue("Host", "CutMinPhotoNum"));

            }
            else
            {
                DateTransfer.CutMinPhotoNum = Convert.ToInt16(CutMinPhotoNumStr);

            }
            string PhotoRemarkFlagStr = IniFile.IniReadValue("Host", "PhotoRemarkFlag");
            if (string.IsNullOrEmpty(PhotoRemarkFlagStr))
            {
                IniFile.IniWriteValue("Host", "PhotoRemarkFlag", "0");
                DateTransfer.PhotoRemarkFlag = Convert.ToInt16(IniFile.IniReadValue("Host", "PhotoRemarkFlag"));

            }
            else
            {
                DateTransfer.PhotoRemarkFlag = Convert.ToInt16(PhotoRemarkFlagStr);
            }
            string SaveFileTypeStr = IniFile.IniReadValue("Host", "SaveFileType");
            if (string.IsNullOrEmpty(SaveFileTypeStr))
            {
                IniFile.IniWriteValue("Host", "SaveFileType", "0");

                DateTransfer.SaveFileType = Convert.ToInt16(IniFile.IniReadValue("Host", "SaveFileType"));

            }
            else
            {
                DateTransfer.SaveFileType = Convert.ToInt16(SaveFileTypeStr);
            }
            string BarCodeTypeStr = IniFile.IniReadValue("Host", "BarCodeType");
            if (string.IsNullOrEmpty(BarCodeTypeStr))
            {
                IniFile.IniWriteValue("Host", "BarCodeType", "1");

                DateTransfer.SelectBarCodeType = Convert.ToInt16(IniFile.IniReadValue("Host", "BarCodeType"));

            }
            else
            {
                DateTransfer.SelectBarCodeType = Convert.ToInt16(BarCodeTypeStr);

            }

            string HistoryDataSaveDays = IniFile.IniReadValue("Host", "HistoryDataSaveDays");
            if (string.IsNullOrEmpty(HistoryDataSaveDays))
            {
                IniFile.IniWriteValue("Host", "HistoryDataSaveDays", "1");

                DateTransfer.HistoryDataSaveDays = Convert.ToInt16(IniFile.IniReadValue("Host", "HistoryDataSaveDays"));

            }
            else
            {
                DateTransfer.HistoryDataSaveDays = Convert.ToInt16(HistoryDataSaveDays);

            }
            //DateTransfer.HistoryDataSaveDays
            string TextAlignTypeStr = IniFile.IniReadValue("Host", "TextAlignType");
            if (string.IsNullOrEmpty(TextAlignTypeStr))
            {
                IniFile.IniWriteValue("Host", "TextAlignType", "0");

                DateTransfer.TextAlignType = Convert.ToInt16(IniFile.IniReadValue("Host", "TextAlignType"));

            }
            else
            {
                DateTransfer.TextAlignType = Convert.ToInt16(TextAlignTypeStr);
            }
            string BackColor = IniFile.IniReadValue("Host", "BackColor");
            if (string.IsNullOrEmpty(BackColor))
            {

                IniFile.IniWriteValue("Host", "BackColor", "128,128,128");
                DateTransfer.ColorBackStr = IniFile.IniReadValue("Host", "BackColor");
            }
            else
            {
                DateTransfer.ColorBackStr = BackColor;
            }
            //DateTransfer.AddIccByPs
            string AddIccByPs = IniFile.IniReadValue("Host", "AddIccByPs");
            if (string.IsNullOrEmpty(AddIccByPs))
            {

                IniFile.IniWriteValue("Host", "AddIccByPs", "0");
                DateTransfer.AddIccByType = Convert.ToInt32(IniFile.IniReadValue("Host", "AddIccByPs"));
            }
            else
            {
                DateTransfer.AddIccByType = Convert.ToInt32(IniFile.IniReadValue("Host", "AddIccByPs"));
            }
            List<BoardModel> bL = _mainBLL.GetErrorList();
            gridControlErrorList.DataSource = bL;
            toolStripStatusLabeleErrorNum.Text = "错误计数:" + bL.Count;
            if (bL.Count == 0)
            {
                this.Size = new Size(MainFormWidth, MainFormSamllHeight);
            }
            else
            {
                this.Size = new Size(MainFormWidth, MainFormBigHeight);
            }
            CurrCutPath = IniFile.IniReadValue("Host", "CutInfo");
            //PhotosizeUnit

            string PhotosizeUnit = IniFile.IniReadValue("Host", "PhotosizeUnit");
            if (string.IsNullOrEmpty(PhotosizeUnit))
            {

                IniFile.IniWriteValue("Host", "PhotosizeUnit", "0");
                DateTransfer.PhotosizeUnit = Convert.ToInt32(IniFile.IniReadValue("Host", "PhotosizeUnit"));
            }
            else
            {
                DateTransfer.PhotosizeUnit = Convert.ToInt32(IniFile.IniReadValue("Host", "PhotosizeUnit"));
            }

            string LineColorString = IniFile.IniReadValue("Host", "LineBackColor");
            if (string.IsNullOrEmpty(LineColorString))
            {
                DateTransfer.LineBackStr = Color.Black.R + "," + Color.Black.G + "," + Color.Black.B;
                IniFile.IniWriteValue("Host", "LineBackColor", Color.Black.R + "," + Color.Black.G + "," + Color.Black.B);

            }
            else
            {
                string[] colorArray = LineColorString.Split(',');
                DateTransfer.LineBackStr = colorArray[0] + "," + colorArray[1] + "," + colorArray[2];
            }
            string RemarkKeysColor = IniFile.IniReadValue("Host", "RemarkKeysColor");
            DateTransfer.RemarkKeysColor = RemarkKeysColor;
            string strCutInfoPosition = IniFile.IniReadValue("Host", "CutInfoPosition");
            if (string.IsNullOrEmpty(strCutInfoPosition))
            {

                IniFile.IniWriteValue("Host", "CutInfoPosition", "0");
                DateTransfer.CutInfoPosition = IniFile.IniReadValue("Host", "CutInfoPosition");
            }
            else
            {
                DateTransfer.CutInfoPosition = strCutInfoPosition;
            }

            string strRemarkInPicBottomOrTop = IniFile.IniReadValue("Host", "RemarkInPicBottomOrTop");
            if (string.IsNullOrEmpty(strRemarkInPicBottomOrTop))
            {
                IniFile.IniWriteValue("Host", "RemarkInPicBottomOrTop", "0");
                DateTransfer.RemarkInPicBottomOrTop = 0;
            }
            else
            {
                DateTransfer.RemarkInPicBottomOrTop = Convert.ToInt32(strRemarkInPicBottomOrTop);
            }
            string strRemarkInPicRightOrLeft = IniFile.IniReadValue("Host", "RemarkInPicRightOrLeft");
            if (string.IsNullOrEmpty(strRemarkInPicRightOrLeft))
            {
                IniFile.IniWriteValue("Host", "RemarkInPicRightOrLeft", "0");
                DateTransfer.RemarkInPicRightOrLeft = 0;
            }
            else
            {
                DateTransfer.RemarkInPicRightOrLeft = Convert.ToInt32(strRemarkInPicRightOrLeft);
            }
            string strTwoCutFlag = IniFile.IniReadValue("Host", "TwoCutFlag");
            if (string.IsNullOrEmpty(strTwoCutFlag))
            {
                IniFile.IniWriteValue("Host", "TwoCutFlag", "False");
            }
            else
            {
                DateTransfer.TwoCutFlag = Convert.ToBoolean(strTwoCutFlag);
            }
            //MerginMMCen = DateTransfer.MerginMM * 10;
            //MerginMMWH = DateTransfer.MerginMM * 2 * 10;
        }
        private void timerCheckHistory_Tick(object sender, EventArgs e)
        {
            try
            {
                backgroundWorkerClear.RunWorkerAsync();
            }
            catch (Exception ex)
            {
            }
        }

        private void backgroundWorkerClear_DoWork(object sender, DoWorkEventArgs e)
        {
            setBll.DelHistoryData(Convert.ToInt16(IniFile.IniReadValue("Host", "HistoryDataSaveDays")));
        }

        private void tsbtnHistoryData_Click(object sender, EventArgs e)
        {
            FrmHistorData frm = new FrmHistorData();
            frm.ShowDialog();
        }

        private void tsbtnBaseInfo_Click(object sender, EventArgs e)
        {
            FrmBaseInfo frm = new FrmBaseInfo();
            frm.ShowDialog();
        }

        private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                this.Visible = false;
            }
            else
            {
                this.Visible = true;
            }
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.ExitThread();
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Visible = false;
            e.Cancel = true;
        }

        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            SetLocation();
            this.Visible = true;
            this.WindowState = FormWindowState.Normal;
        }

        private string GetHeadTxt()
        {
            string headMsg = "渲染大图";
            if (Convert.ToInt16(IniFile.IniReadValue("Host", "FontSize")) <= 0)
            {
                headMsg += "字体大小:" + FontSize;
                //FontSize = 40;
            }
            else
            {
                int FontSize = Convert.ToInt16(IniFile.IniReadValue("Host", "FontSize"));
                headMsg += "字体大小:" + FontSize;

            }


            return headMsg;
        }

        //得到该图片字体的颜色
        private Color GetFontColorByPhotoInfo(PhotoInfo_MakeBigPic picInfo)
        {
            Color fontColor = Color.Black;

            if (picInfo.Priority >= 10)
            {
                fontColor = Color.Blue;
            }
            else if (picInfo.Priority >= 6)
            {
                fontColor = Color.Red;
            }

            if (picInfo.BasePhotoInfo.IsClearBox)
            {
                fontColor = Color.Green;
            }
            return fontColor;
        }

        //根据图片信息得到一个中间图，包含条码
        private RasterImage CreateMidImg(PhotoInfo_MakeBigPic picInfo)
        {
            int midPicWidth = 0, midPicHeight = 0;//中间图的宽高
            switch (picInfo.barCodeStatus)
            {
                case SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom://条码在下方
                    if (picInfo.IsWhirl)//旋转
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixHeight;
                        midPicHeight = picInfo.BasePhotoInfo.PixWidth + BARCODEHEIDHT;
                    }
                    else
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixWidth;
                        midPicHeight = picInfo.BasePhotoInfo.PixHeight + BARCODEHEIDHT;
                    }
                    break;
                case SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft://条码在右边
                    if (picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixHeight + BARCODEHEIDHT;
                        midPicHeight = picInfo.BasePhotoInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixWidth + BARCODEHEIDHT;
                        midPicHeight = picInfo.BasePhotoInfo.PixHeight;
                    }
                    break;
                case SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode: //无条码
                    if (picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixHeight;
                        midPicHeight = picInfo.BasePhotoInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixWidth;
                        midPicHeight = picInfo.BasePhotoInfo.PixHeight;
                    }
                    break;
            }
            RasterImage midImg = new RasterImage(RasterMemoryFlags.Conventional, midPicWidth, midPicHeight, 24, RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, IntPtr.Zero, 0);

            FillCommand midfcommand = new FillCommand();//填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            midfcommand.Run(midImg);
            return midImg;
        }
        //根据图片信息得到一个中间图，包含条码
        private RasterImage CreateMidImgV(PhotoInfo_MakeBigPic picInfo)
        {
            int midPicWidth = 0, midPicHeight = 0;//中间图的宽高
            switch (picInfo.barCodeStatus)
            {
                case SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft://条码在下方
                    if (!picInfo.IsWhirl)//旋转
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixHeight;
                        midPicHeight = picInfo.BasePhotoInfo.PixWidth + BARCODEHEIDHT;
                    }
                    else
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixWidth;
                        midPicHeight = picInfo.BasePhotoInfo.PixHeight + BARCODEHEIDHT;
                    }
                    break;
                case SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom://条码在右边
                    if (!picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixHeight + BARCODEHEIDHT;
                        midPicHeight = picInfo.BasePhotoInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixWidth + BARCODEHEIDHT;
                        midPicHeight = picInfo.BasePhotoInfo.PixHeight;
                    }
                    break;
                case SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode: //无条码
                    if (!picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixHeight;
                        midPicHeight = picInfo.BasePhotoInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixWidth;
                        midPicHeight = picInfo.BasePhotoInfo.PixHeight;
                    }
                    break;
            }
            RasterImage midImg = new RasterImage(RasterMemoryFlags.Conventional, midPicWidth, midPicHeight, 24, RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, IntPtr.Zero, 0);

            FillCommand midfcommand = new FillCommand();//填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            midfcommand.Run(midImg);

            return midImg;
        }
        /// <summary>
        ///根据图片信息得到一个中间图横方向的，包含条码
        /// 
        /// </summary>
        /// <param name="picInfo"></param>
        /// <returns></returns>
        private RasterImage CreateMidImgH(PhotoInfo_MakeBigPic picInfo)
        {
            int midPicWidth = 0, midPicHeight = 0;//中间图的宽高
            switch (picInfo.barCodeStatus)
            {
                case SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft://条码在左右
                    if (picInfo.IsWhirl)//旋转
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixHeight + BARCODEHEIDHT;
                        midPicHeight = picInfo.BasePhotoInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixWidth + BARCODEHEIDHT;
                        midPicHeight = picInfo.BasePhotoInfo.PixHeight;
                    }
                    break;
                case SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom://条码在上下
                    if (picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixHeight;
                        midPicHeight = picInfo.BasePhotoInfo.PixWidth + BARCODEHEIDHT;
                    }
                    else
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixWidth;
                        midPicHeight = picInfo.BasePhotoInfo.PixHeight + BARCODEHEIDHT;
                    }
                    break;
                case SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode: //无条码
                    if (picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixHeight;
                        midPicHeight = picInfo.BasePhotoInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.BasePhotoInfo.PixWidth;
                        midPicHeight = picInfo.BasePhotoInfo.PixHeight;
                    }
                    break;
            }
            RasterImage midImg = new RasterImage(RasterMemoryFlags.Conventional, midPicWidth, midPicHeight, 24, RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, IntPtr.Zero, 0);

            FillCommand midfcommand = new FillCommand();//填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            midfcommand.Run(midImg);

            return midImg;
        }
        //建立每张待生成的小图片
        private RasterImage CreatePicImg(PhotoInfo_MakeBigPic picInfo, RasterCodecs codes, BoardInfo_MakeBigPic board)
        {
            UPTLab("正在加载图片...");
            RasterImage smallPicImage = null;
            try
            {
                if (File.Exists(Application.StartupPath + "\\tem.jpg"))
                {
                    File.Delete(Application.StartupPath + "\\tem.jpg");
                }
            }
            catch { }

            SizeCommand command = new SizeCommand();//改变大小,因为在分配打印机时由于四舍五入的原因改变过图像的大小

            if (picInfo.IsWhirl)
            {
                if (picInfo.BasePhotoInfo.PixWidth >= 18898 || picInfo.BasePhotoInfo.PixHeight >= 18898)//大于这个尺寸就用PS进行旋转
                {
                    //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                    //myClass.DoRotate(picInfo.BasePhotoInfo.PicPath, Application.StartupPath + "\\tem.jpg", true, 270);

                    psApp.RotatePic(picInfo.BasePhotoInfo.PicPath, Application.StartupPath + "\\tem.jpg", 270);

                    smallPicImage = codes.Load(Application.StartupPath + "\\tem.jpg");
                }
                else
                {
                    smallPicImage = codes.Load(picInfo.BasePhotoInfo.PicPath);
                    RotateCommand rc = new RotateCommand();

                    rc.Angle = 270 * 100;
                    rc.FillColor = new RasterColor(255, 255, 255);
                    rc.Flags = RotateCommandFlags.Resize;
                    UPTLab("正在旋转...");
                    rc.Run(smallPicImage);
                }

                command.Width = picInfo.BasePhotoInfo.PixHeight;
                command.Height = picInfo.BasePhotoInfo.PixWidth;
            }
            else
            {
                smallPicImage = codes.Load(picInfo.BasePhotoInfo.PicPath);
                command.Width = picInfo.BasePhotoInfo.PixWidth;
                command.Height = picInfo.BasePhotoInfo.PixHeight;
            }
            UPTLab("正在调整图片模式...");
            if (smallPicImage.BitsPerPixel == 8)//判断是否灰度
            {
                ColorResolutionCommand colorRes = new ColorResolutionCommand();
                colorRes.Mode = ColorResolutionCommandMode.InPlace;
                colorRes.BitsPerPixel = 24;
                colorRes.DitheringMethod = RasterDitheringMethod.None;
                colorRes.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
                colorRes.Colors = 0;
                colorRes.Run(smallPicImage);

            }
            UPTLab("正在调整大小...");
            command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
            command.Run(smallPicImage);

            return smallPicImage;
        }
        RasterSizeFlags ReSizeModel(int srcWidth, int srcHeight, int toWidth, int toHeigth)
        {
            RasterSizeFlags rtnFlag = RasterSizeFlags.Resample;
            //if (srcWidth >= toWidth || srcHeight >= toHeigth)
            //{
            //    rtnFlag = RasterSizeFlags.Resample;
            //}
            //else
            //{
            //    rtnFlag = RasterSizeFlags.Bicubic;
            //}
            rtnFlag = RasterSizeFlags.Bicubic;
            return rtnFlag;
        }
        /// <summary>
        /// 竖版用获取图片
        /// </summary>
        /// <param name="picInfo"></param>
        /// <param name="codes"></param>
        /// <param name="board"></param>
        /// <returns></returns>
        private RasterImage CreatePicImgV(PhotoInfo_MakeBigPic picInfo, RasterCodecs codes, BoardInfo_MakeBigPic board)
        {
            UPTLab("正在加载图片...");
            RasterImage smallPicImage = null;
            string temFile = Application.StartupPath + "\\tem.tif";
            try
            {
                if (File.Exists(temFile))
                {
                    File.Delete(temFile);
                }
            }
            catch { }

            SizeCommand command = new SizeCommand();//改变大小,因为在分配打印机时由于四舍五入的原因改变过图像的大小


            string inPath = picInfo.BasePhotoInfo.PicPath;
            if (!picInfo.IsWhirl)
            {
                if (picInfo.BasePhotoInfo.PixWidth >= 10000 || picInfo.BasePhotoInfo.PixHeight >= 10000)
                {
                    string ExeFilePath = Application.StartupPath + "\\RotateImage.exe";
                    UPTLab("正在旋转......" + inPath);


                    using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                    {
                        pExecuteEXE.StartInfo.FileName = ExeFilePath;

                        pExecuteEXE.StartInfo.Arguments = inPath + "*" + temFile + "*" + picInfo.BasePhotoInfo.PixHeight + "*" + picInfo.BasePhotoInfo.PixWidth;

                        pExecuteEXE.Start();
                        pExecuteEXE.WaitForExit();
                    }

                    if (!File.Exists(temFile))
                    {
                        throw new Exception("旋转暂存文件读取失败EX" + inPath);
                    }
                    smallPicImage = codes.Load(temFile);
                    command.Width = picInfo.BasePhotoInfo.PixHeight;
                    command.Height = picInfo.BasePhotoInfo.PixWidth;
                    UPTLab("正在调整大小..." + inPath);
                    command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
                    command.Run(smallPicImage);
                }
                else
                {

                    UPTLab("正在调整大小..." + inPath);
                    smallPicImage = codes.Load(picInfo.BasePhotoInfo.PicPath);
                    command.Width = picInfo.BasePhotoInfo.PixWidth;
                    command.Height = picInfo.BasePhotoInfo.PixHeight;

                    command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
                    command.Run(smallPicImage);
                    UPTLab("正在旋转..." + inPath);

                    RotateCommand rc = new RotateCommand();

                    rc.Angle = 270 * 100;
                    rc.FillColor = new RasterColor(255, 255, 255);
                    rc.Flags = RotateCommandFlags.Resize;

                    rc.Run(smallPicImage);

                }

            }
            else
            {
                ///不需要旋转
                UPTLab("正在调整大小..." + inPath);
                smallPicImage = codes.Load(picInfo.BasePhotoInfo.PicPath);
                command.Width = picInfo.BasePhotoInfo.PixWidth;
                command.Height = picInfo.BasePhotoInfo.PixHeight;

                command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
                command.Run(smallPicImage);

            }



            UPTLab("正在调整图片模式...");
            if (smallPicImage.BitsPerPixel != 24)//判断是否灰度
            {
                ColorResolutionCommand colorRes = new ColorResolutionCommand();
                colorRes.Mode = ColorResolutionCommandMode.InPlace;
                colorRes.BitsPerPixel = 24;
                colorRes.DitheringMethod = RasterDitheringMethod.None;
                colorRes.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
                colorRes.Colors = 0;
                colorRes.Run(smallPicImage);

            }

            return smallPicImage;
        }
        /// <summary>
        /// 横向生成用获取图像
        /// </summary>
        /// <param name="picInfo"></param>
        /// <param name="codes"></param>
        /// <param name="board"></param>
        /// <returns></returns>
        private RasterImage CreatePicImgH(PhotoInfo_MakeBigPic picInfo, RasterCodecs codes, BoardInfo_MakeBigPic board)
        {
            UPTLab("正在加载图片...");
            RasterImage smallPicImage = null;
            string temFile = Application.StartupPath + "\\tem.tif";
            try
            {
                if (File.Exists(temFile))
                {
                    File.Delete(temFile);
                }
            }
            catch { }

            SizeCommand command = new SizeCommand();//改变大小,因为在分配打印机时由于四舍五入的原因改变过图像的大小


            string inPath = picInfo.BasePhotoInfo.PicPath;
            if (picInfo.IsWhirl)
            {
                if (picInfo.BasePhotoInfo.PixWidth >= 10000 || picInfo.BasePhotoInfo.PixHeight >= 10000)
                {
                    UPTLab("正在旋转......");
                    string ExeFilePath = Application.StartupPath + "\\RotateImage.exe";


                    using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                    {
                        pExecuteEXE.StartInfo.FileName = ExeFilePath;

                        pExecuteEXE.StartInfo.Arguments = inPath + "*" + temFile + "*" + picInfo.BasePhotoInfo.PixHeight + "*" + picInfo.BasePhotoInfo.PixWidth;

                        pExecuteEXE.Start();
                        pExecuteEXE.WaitForExit();
                    }
                    if (!File.Exists(temFile))
                    {
                        throw new Exception("旋转暂存文件读取失败EX" + inPath);
                    }
                    smallPicImage = codes.Load(temFile);
                    command.Width = picInfo.BasePhotoInfo.PixHeight;
                    command.Height = picInfo.BasePhotoInfo.PixWidth;
                    UPTLab("正在调整大小...");
                    command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
                    command.Run(smallPicImage);
                }
                else
                {


                    UPTLab("正在旋转...");
                    smallPicImage = codes.Load(picInfo.BasePhotoInfo.PicPath);
                    RotateCommand rc = new RotateCommand();

                    rc.Angle = 270 * 100;
                    rc.FillColor = new RasterColor(255, 255, 255);
                    rc.Flags = RotateCommandFlags.Resize;

                    rc.Run(smallPicImage);
                    UPTLab("正在调整大小...");

                    command.Width = picInfo.BasePhotoInfo.PixHeight;
                    command.Height = picInfo.BasePhotoInfo.PixWidth;

                    command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
                    command.Run(smallPicImage);

                }

            }
            else
            {
                ///不需要旋转
                UPTLab("正在调整大小...");
                smallPicImage = codes.Load(picInfo.BasePhotoInfo.PicPath);
                command.Width = picInfo.BasePhotoInfo.PixWidth;
                command.Height = picInfo.BasePhotoInfo.PixHeight;

                command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
                command.Run(smallPicImage);

            }



            UPTLab("正在调整图片模式...");
            if (smallPicImage.BitsPerPixel != 24)//判断是否灰度
            {
                ColorResolutionCommand colorRes = new ColorResolutionCommand();
                colorRes.Mode = ColorResolutionCommandMode.InPlace;
                colorRes.BitsPerPixel = 24;
                colorRes.DitheringMethod = RasterDitheringMethod.None;
                colorRes.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
                colorRes.Colors = 0;
                colorRes.Run(smallPicImage);

            }

            return smallPicImage;
        }
        private RasterImage CreatePicImg2Cmyk(PhotoInfo_MakeBigPic picInfo, RasterCodecs codes, BoardInfo_MakeBigPic board)
        {
            UPTLab("正在加载图片...");
            RasterImage smallPicImage = null;
            string temFile = Application.StartupPath + "\\tem.tif";
            try
            {
                if (File.Exists(temFile))
                {
                    File.Delete(temFile);
                }
            }
            catch { }

            SizeCommand command = new SizeCommand();//改变大小,因为在分配打印机时由于四舍五入的原因改变过图像的大小


            string inPath = picInfo.BasePhotoInfo.PicPath;
            if (!picInfo.IsWhirl)
            {
                UPTLab("正在调整大小...");
                smallPicImage = codes.LoadCmykPlanes(picInfo.BasePhotoInfo.PicPath, 8, 1);
                command.Width = picInfo.BasePhotoInfo.PixWidth - 2 * DateTransfer.BoardLineWidth;
                command.Height = picInfo.BasePhotoInfo.PixHeight - 2 * DateTransfer.BoardLineWidth;

                command.Flags = RasterSizeFlags.Resample;
                smallPicImage.Page = 1;
                command.Run(smallPicImage);
                smallPicImage.Page = 2;
                command.Run(smallPicImage);
                smallPicImage.Page = 3;
                command.Run(smallPicImage);
                smallPicImage.Page = 4;
                command.Run(smallPicImage);
                UPTLab("正在旋转...");

                RotateCommand rc = new RotateCommand();

                rc.Angle = 270 * 100;
                rc.FillColor = new RasterColor(255, 255, 255);
                rc.Flags = RotateCommandFlags.Resize;
                smallPicImage.Page = 1;
                rc.Run(smallPicImage);
                smallPicImage.Page = 2;
                rc.Run(smallPicImage);
                smallPicImage.Page = 3;
                rc.Run(smallPicImage);
                smallPicImage.Page = 4;
                rc.Run(smallPicImage);

            }
            else
            {
                ///不需要旋转
                UPTLab("正在调整大小...");
                smallPicImage = codes.LoadCmykPlanes(picInfo.BasePhotoInfo.PicPath, 8, 1);
                command.Width = picInfo.BasePhotoInfo.PixWidth - 2 * DateTransfer.BoardLineWidth;
                command.Height = picInfo.BasePhotoInfo.PixHeight - 2 * DateTransfer.BoardLineWidth;

                command.Flags = RasterSizeFlags.Resample;
                smallPicImage.Page = 1;
                command.Run(smallPicImage);
                smallPicImage.Page = 2;
                command.Run(smallPicImage);
                smallPicImage.Page = 3;
                command.Run(smallPicImage);
                smallPicImage.Page = 4;
                command.Run(smallPicImage);
            }



            //UPTLab("正在调整图片模式...");
            //if (smallPicImage.BitsPerPixel != 24)//判断是否灰度
            //{
            //    ColorResolutionCommand colorRes = new ColorResolutionCommand();
            //    colorRes.Mode = ColorResolutionCommandMode.InPlace;
            //    colorRes.BitsPerPixel = 24;
            //    colorRes.DitheringMethod = RasterDitheringMethod.None;
            //    colorRes.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
            //    colorRes.Colors = 0;
            //    smallPicImage.Page = 1;
            //    colorRes.Run(smallPicImage);
            //    smallPicImage.Page = 2;
            //    colorRes.Run(smallPicImage);
            //    smallPicImage.Page = 3;
            //    colorRes.Run(smallPicImage);
            //    smallPicImage.Page = 4;
            //    colorRes.Run(smallPicImage);


            //}
            // string File1= @"D:\Projects\newSmallERP\SmallERP\SmallERP.Host\bin\Debug\12345.tif";
            //codes.SaveCmykPlanes(smallPicImage,, RasterImageFormat.TifCmyk, 24);
            // codes.SaveCmykPlanes(smallPicImage, File1, RasterImageFormat.TifCmyk, 0, 1, CodecsSavePageMode.Replace);

            return smallPicImage;
        }
        //如果有条码，建立条码图片“包含色块、条码、文字”等信息
        private RasterImage CreateBarCodeImg(PhotoInfo_MakeBigPic picInfo, RasterImage midImageTmp, BoardInfo_MakeBigPic board)
        {
            int barCodeImageWidth;//条码图片的宽度,高度是固定的，因为在建图片是“横向建立”
            RasterImage barcodeImageTemp;
            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom)//左边、右边放条码
            {
                barCodeImageWidth = midImageTmp.Height;
            }
            else
            {
                barCodeImageWidth = midImageTmp.Width;
            }

            barcodeImageTemp = new RasterImage(
                                                        RasterMemoryFlags.Conventional,
                                                        barCodeImageWidth,
                                                        BARCODEHEIDHT,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);

            //设置条码图片的DPI这样才能扫描时更精确
            FillCommand fcBarcode = new FillCommand();
            fcBarcode.Color = new RasterColor(255, 255, 255);
            barcodeImageTemp.XResolution = board.BoardBaseInfo.DPI;
            barcodeImageTemp.YResolution = board.BoardBaseInfo.DPI;
            fcBarcode.Run(barcodeImageTemp);

            FillCommand midfcommand = new FillCommand();//填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            if (DateTransfer.PhotoRemarkFlag == 1)
            {
                int cInt = picInfo.BasePhotoInfo.OrderProductId % 10;
                RasterColor color = GetColor(cInt);
                midfcommand.Color = color;
            }
            else
            {
                midfcommand.Color = new RasterColor(255, 255, 255);
            }

            midfcommand.Run(barcodeImageTemp);
            return barcodeImageTemp;
        }
        //如果有条码，建立条码图片“包含色块、条码、文字”等信息
        private RasterImage CreateBarCodeImg(PhotoInfo_MakeBigPic picInfo, RasterImage midImageTmp, BoardInfo_MakeBigPic board, out Color BackColor)
        {
            int barCodeImageWidth;//条码图片的宽度,高度是固定的，因为在建图片是“横向建立”
            RasterImage barcodeImageTemp;
            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom)//左边、右边放条码
            {
                barCodeImageWidth = midImageTmp.Height;
            }
            else
            {
                barCodeImageWidth = midImageTmp.Width;
            }

            barcodeImageTemp = new RasterImage(
                                                        RasterMemoryFlags.Conventional,
                                                        barCodeImageWidth,
                                                        BARCODEHEIDHT,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);


            FillCommand fcBarcode = new FillCommand();
            fcBarcode.Color = new RasterColor(255, 255, 255);
            barcodeImageTemp.XResolution = board.BoardBaseInfo.DPI;
            barcodeImageTemp.YResolution = board.BoardBaseInfo.DPI;
            fcBarcode.Run(barcodeImageTemp);

            FillCommand midfcommand = new FillCommand();//填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            if (DateTransfer.PhotoRemarkFlag == 1)
            {
                int cInt = picInfo.BasePhotoInfo.OrderProductId % 30;
                RasterColor color = GetColor(cInt);
                midfcommand.Color = color;
                BackColor = Color.FromArgb(color.R, color.G, color.B);
            }
            else
            {
                midfcommand.Color = new RasterColor(255, 255, 255);
                BackColor = Color.FromArgb(255, 255, 255);
            }

            midfcommand.Run(barcodeImageTemp);
            return barcodeImageTemp;
        }
        //如果有条码，建立条码图片“包含色块、条码、文字”等信息
        private RasterImage CreateBarCodeImgV(PhotoInfo_MakeBigPic picInfo, RasterImage midImageTmp, BoardInfo_MakeBigPic board, out Color BackColor)
        {
            int barCodeImageWidth;//条码图片的宽度,高度是固定的，因为在建图片是“横向建立”
            RasterImage barcodeImageTemp;
            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom)//上下
            {
                barCodeImageWidth = midImageTmp.Width;
            }
            else
            {
                barCodeImageWidth = midImageTmp.Height;
            }

            barcodeImageTemp = new RasterImage(
                                                        RasterMemoryFlags.Conventional,
                                                        barCodeImageWidth,
                                                        BARCODEHEIDHT,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);

            //设置条码图片的DPI这样才能扫描时更精确
            FillCommand fcBarcode = new FillCommand();
            fcBarcode.Color = new RasterColor(255, 255, 255);
            barcodeImageTemp.XResolution = board.BoardBaseInfo.DPI;
            barcodeImageTemp.YResolution = board.BoardBaseInfo.DPI;
            fcBarcode.Run(barcodeImageTemp);

            FillCommand midfcommand = new FillCommand();//填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            if (DateTransfer.PhotoRemarkFlag == 1)
            {
                int cInt = picInfo.BasePhotoInfo.OrderProductId % 30;
                RasterColor color = GetColor(cInt);
                midfcommand.Color = color;
                BackColor = Color.FromArgb(color.R, color.G, color.B);
            }
            else
            {
                midfcommand.Color = new RasterColor(255, 255, 255);
                BackColor = Color.FromArgb(255, 255, 255);
            }

            midfcommand.Run(barcodeImageTemp);
            return barcodeImageTemp;
        }
        //#endregion

        // #region 渲染大图
        Bleed curBleed = new Bleed(0, 0);
        private string _curCutFileFullPath = "";
        private bool _cutNoBarcode = false;

        private void StratWork()
        {
            BoardInfo_MakeBigPic boardInfo;
            while (true)
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                _cutNoBarcode = false;
                DateTransfer.TwoCutFlag = false;
                _curCutFileFullPath = "";
                curBleed = DateTransfer.CurrentBleed;
                UPTLab("正在获取新的大板信息....");
                int result = _mainBLL.GetOneBoard(out boardInfo);
                UPTLab("获取成功....");
                _cutNoBarcode = DateTransfer.CutNobarCode;
                if (result == 1)
                {
                    if (boardInfo.BoardBaseInfo.BoardProcudtType == 0)
                    {
                        _cutNoBarcode = false;
                        DateTransfer.TwoCutFlag = false;
                    }
                    else
                    {
                        _cutNoBarcode = true;
                        DateTransfer.TwoCutFlag = true;
                    }

                    UPTLabBoardName(boardInfo.BoardBaseInfo.PicPath.Substring(boardInfo.BoardBaseInfo.PicPath.LastIndexOf("\\")));
                    string BoolFilePrinterName = IniFile.IniReadValue("Host", "BoolFilePrinterName");
                    string folderName = boardInfo.BoardBaseInfo.PicPath.Substring(0, boardInfo.BoardBaseInfo.PicPath.LastIndexOf("\\"));
                    string fileName = boardInfo.BoardBaseInfo.PicPath.Substring(boardInfo.BoardBaseInfo.PicPath.LastIndexOf("\\") + 1);
                    string tempFolderName = "";
                    if (!string.IsNullOrEmpty(BoolFilePrinterName) && Convert.ToBoolean(BoolFilePrinterName) && folderName.IndexOf("-" + boardInfo.PrinterName.Trim()) < 0)
                    {
                        tempFolderName = tempFolderName + "-" + boardInfo.PrinterName.Trim();
                    }
                    string BoolTempleteName = IniFile.IniReadValue("Host", "BoolTempleteName");
                    //string boardWidth=(boardInfo.BoardBaseInfo.Height/boardInfo.BoardBaseInfo.DPI).ToString("0.0");
                    BoolTempleteName = string.IsNullOrEmpty(BoolTempleteName) ? "false" : BoolTempleteName;
                    if (Convert.ToBoolean(BoolTempleteName) && folderName.IndexOf("-" + boardInfo.BoardTemlpeteInfo.TemplateName) < 0)
                    {
                        tempFolderName = tempFolderName + "-" + boardInfo.BoardTemlpeteInfo.TemplateName;
                    }
                    if (!string.IsNullOrEmpty(tempFolderName))
                    {
                        boardInfo.BoardBaseInfo.PicPath = folderName + "\\" + tempFolderName + "\\" + fileName;
                    }
                    else
                    {
                        boardInfo.BoardBaseInfo.PicPath = folderName + "\\" + fileName;

                    }

                    _curCutFileFullPath = CurrCutPath + "\\" + boardInfo.BoardBaseInfo.BoardId + ".txt";
                    string boardPath = boardInfo.BoardBaseInfo.PicPath.Substring(0, boardInfo.BoardBaseInfo.PicPath.LastIndexOf("\\"));
                    if (!Directory.Exists(boardPath))
                    {
                        Directory.CreateDirectory(boardPath);
                    }
                    _mainBLL.ReNameBoardPath(boardInfo.BoardBaseInfo.BoardId, boardInfo.BoardBaseInfo.PicPath);
                    UPTLabBoardCount(boardInfo.AllCount);
                    if (boardInfo == null || boardInfo.BoardBaseInfo.BoardId == 0)
                    {
                        UPTLab("boardInfo为NULL或是BOARDID=0");
                        continue;
                    }
                    else
                    {
                        if (boardInfo.PhotoS.Count < 1)
                        {
                            BoardBLL.UpdateBoard(boardInfo.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, "此大板的照片已被移除");
                            continue;
                        }
                        else
                        {
                            //if (boardInfo.PrinterType == 0)
                            //{
                            //    if (boardInfo.IsHorizontal)
                            //    {
                            //        MakeBigPicV2(boardInfo);
                            //    }
                            //    else
                            //    {
                            //        MakeBigPicH2(boardInfo);
                            //    }
                            //}
                            //else
                            //{
                            //    MakeBigPicH2Cmyk(boardInfo);
                            //}


                            UPTLab("生成大板成功！");
                            MakeBigPicH2VCutBeforePic(boardInfo);
                            //if (boardInfo.PrinterType == 0)
                            //{
                            //    if (boardInfo.IsTransverse && boardInfo.PhotoS.Count > DateTransfer.CutMinPhotoNum)//是否裁切
                            //    {
                            //        if (boardInfo.IsHorizontal)
                            //        {
                            //            if (DateTransfer.CutInfoPosition == "0")
                            //            {
                            //                MakeBigPicH2HCutBeforePic(boardInfo);
                            //            }
                            //            else
                            //            {
                            //                MakeBigPicH2HCutAfterPic(boardInfo);
                            //            }
                            //        }
                            //        else
                            //        {
                            //            if (DateTransfer.CutInfoPosition == "0")
                            //            {
                            //                MakeBigPicH2VCutBeforePic(boardInfo);
                            //            }
                            //            else
                            //            {
                            //                MakeBigPicH2VCutAfterPic(boardInfo);
                            //            }
                            //        }
                            //    }
                            //    else
                            //    {
                            //        if (boardInfo.IsHorizontal)
                            //        {
                            //            MakeBigPicV2(boardInfo);
                            //        }
                            //        else
                            //        {
                            //            MakeBigPicH2(boardInfo);
                            //        }
                            //    }
                            //}
                            //else
                            //{
                            //    MakeBigPicH2Cmyk(boardInfo);
                            //}
                            UPTLab("生成大板成功！");
                        }

                    }
                }
                else if (result == -4)//没有可用的格子了就暂停30秒后再试
                {
                    UPTLab("没有板可生成或是格子已占满");
                    UPTLabBoardCount("0");
                    Thread.Sleep(10 * 1000);
                }
                else if (result == -5)
                {
                    UPTLab("数据错误，请修复数据");
                    SetErrorMsg(CONNERR);
                    Thread.Sleep(10 * 1000);
                }
                else if (result == -2)
                {
                    UPTLab("解密时出错");
                    Thread.Sleep(10 * 1000);
                }
                else
                {
                    UPTLab("与配置文件联接异常，请检查配置文件是否存在或修复数据");
                    Thread.Sleep(10 * 1000);
                }
            }
        }
        //EAN.ClassInterfaceClass cifi = new EAN.ClassInterfaceClass();
        delegate void MakeBigPicDelegate(BoardInfo_MakeBigPic board);

        Color GetRemarkColor(string inPath)
        {
            Color c = Color.FromArgb(0, 0, 0);
            foreach (string keyValues in DateTransfer.RemarkKeysColor.Split('#'))
            {

                string[] keyValue = keyValues.Split('@');

                if (string.IsNullOrEmpty(keyValue[0]))
                {
                    continue;
                }
                else
                {
                    if (inPath.Contains("不" + keyValue[0]))
                    {
                        continue;
                    }
                    string[] colorarray = keyValue[1].Split(',');
                    int R = Convert.ToInt16(colorarray[0]);
                    int G = Convert.ToInt16(colorarray[1]);
                    int B = Convert.ToInt16(colorarray[2]);
                    if (inPath.Contains(keyValue[0]))
                    {
                        c = Color.FromArgb(R, G, B);
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }

            }
            return c;

        }
        private void MakeBigPicH(BoardInfo_MakeBigPic board)
        {
            int XExcursion = 0;//X坐标偏移量
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            //int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            //int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            int boardPixWidth = board.BoardBaseInfo.Height; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.Length;//大图的高,相素高宽互换

            //XExcursion = boardPixWidth;
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸
            if (PicFormat == 1 || BoardPixHeight > 25400)
            {
                PicFormat = 1;
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }

            DateTransfer.IsAutoCut = board.IsTransverse;

            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {

                RasterCodecs codecs = new RasterCodecs();
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    boardPixWidth,//+1保证最右边的框线可以出来
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                Color backColor = DateTransfer.BackColor;

                FillCommand fcommand = new FillCommand();
                //fcommand.Color = new RasterColor(128, 128, 128);
                fcommand.Color = new RasterColor(backColor);
                fcommand.Run(destImage);

                UPTLab("渲染大图框架成功");
                foreach (var picInfo in board.PhotoS)
                {
                    UPTLab("正在添加小图:" + picInfo.BasePhotoInfo.PhotoId);
                    try
                    {
                        // #region 将所有的小图都粘贴到大图上
                        // 根据加急级别以及是否清空等确定字体的颜色

                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        if (!string.IsNullOrEmpty(DateTransfer.RemarkKeysColor))
                        {
                            FontColor = GetRemarkColor(picInfo.BasePhotoInfo.PicPath);

                        }
                        RasterImage smallPicImage = CreatePicImg(picInfo, codecs, board);//小图片
                        RasterImage midImageTmp = CreateMidImg(picInfo);//带有条码的中间图
                        UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)

                        //是否有条码
                        if (picInfo.barCodeStatus != SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode)//有条码
                        {
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board);//条码图片的临时图片

                            //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            RasterImage ColorImgBlock = GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                            UPTLab("粘贴色块");
                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                             0,
                             0,
                             barcodeImageTemp.Width,
                             barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);


                            UPTLab("生成条码及文字");

                            #region 打印条码及文字信息
                            Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            int recX = ColorImgBlock.Width + 5, recY = -2;
                            string Barcode = "";
                            string nullBar = " ";
                            SizeF sizeF;
                            if (DateTransfer.SelectBarCodeType == 1)
                            {
                                recX += 20;
                                //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                            }
                            else if (DateTransfer.SelectBarCodeType == 3)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('『');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('』');
                                if (startIndex == -1 || endIndex == -1)
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }
                                else
                                {
                                    string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                    //if (IsNum(tempBarcode))
                                    //{
                                    //    Barcode = "*" + tempBarcode + "*";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    //else
                                    //{
                                    //    Barcode = "";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    Barcode = "*" + tempBarcode + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                                }

                            }
                            else if (DateTransfer.SelectBarCodeType == 0)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                Barcode = "*" + picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1) + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                            }
                            else if (DateTransfer.SelectBarCodeType == 3)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('『');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('』');
                                if (startIndex == -1 || endIndex == -1)
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }
                                else
                                {
                                    string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                    //if (IsNum(tempBarcode))
                                    //{
                                    //    Barcode = "*" + tempBarcode + "*";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    //else
                                    //{
                                    //    Barcode = "";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    Barcode = "*" + tempBarcode + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                                }
                            }
                            else
                            {
                                Barcode = "";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                            }

                            BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度

                            //色块就有50
                            //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                processor.Draw3dText(g,
                                                   Barcode,
                                                     rc,
                                                     SpecialEffectsTextStyle.Normal,
                                                     SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                     0, /* horizontal  shadow position */
                                                     0, /* vertical shadow position */
                                                     Color.Black, /* text color, blue */
                                                     Color.White,/* shadow color, black */
                                                     Color.White, /* border color, white */
                                                     textBarFont3o9,
                                                     null);

                                recX += BARCODEWIDTH;
                            }
                            else
                            {

                            }


                            //写其文字信息

                            recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            string productName = "";
                            string leftProduct = "";
                            picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                            int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                            if (PIndex > 0)
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex + 1);
                            }
                            else
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName;
                                leftProduct = "-";
                            }



                            Rectangle rcFont = new Rectangle(recX - 20, -3, barcodeImageTemp.Width - recX, BARCODEHEIDHT);
                            string text = "";
                            try
                            {
                                text = GetBarCodeStringByCutsom(picInfo, board);
                            }
                            catch
                            {

                            }
                            processor.Draw3dText(g,
                                                text,
                                                rcFont,
                                                SpecialEffectsTextStyle.Normal,
                                                SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                0, /* horizontal  shadow position */
                                                0, /* vertical shadow position */
                                                FontColor,/* text color, blue */
                                                Color.White,/* shadow color, black */
                                                Color.White, /* border color, white */
                                                textFont,
                                                null);

                            g.Dispose();
                            ColorImgBlock.Dispose();//释放色块的资源
                            #endregion

                            UPTLab("向中间图片mdiImageTemp图贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            Rectangle barCodeRec, picRec;

                            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左\右边
                            {
                                RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                rcBarcode.Angle = 270 * 100;
                                rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                rcBarcode.Flags = RotateCommandFlags.Resize;
                                rcBarcode.Run(barcodeImageTemp);

                                //barCodeRec = new Rectangle(0, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                                //picRec = new Rectangle(BARCODEHEIDHT, 0, smallPicImage.Width, smallPicImage.Height);

                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIDHT, barcodeImageTemp.Height);

                            }
                            else  //0:条码放在下面
                            {
                                //barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, BARCODEHEIDHT);
                                //picRec = new Rectangle(0, BARCODEHEIDHT, smallPicImage.Width, smallPicImage.Height);

                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, BARCODEHEIDHT);
                            }

                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            cfcBarcode.SourcePoint = Point.Empty;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.DestinationImage = midImageTmp;


                            //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                            //{
                            //    UPTLab("对条码进行锐化");
                            //    SharpenCommand command = new SharpenCommand();
                            //    command.Sharpness = 950;
                            //    command.Run(barcodeImageTemp);
                            //}

                            UPTLab("贴条码");
                            //贴条码
                            cfcBarcode.DestinationRectangle = barCodeRec;
                            cfcBarcode.Run(barcodeImageTemp);

                            UPTLab("贴图片");
                            //贴图片
                            cfcBarcode.DestinationRectangle = picRec;
                            cfcBarcode.Run(smallPicImage);

                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                            #endregion

                        }
                        else//无条码
                        {
                            if (DateTransfer.IsPrintBarCodeInPicture)
                            {
                                RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board);//条码图片的临时图片

                                //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                                RasterImage ColorImgBlock = GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                                UPTLab("粘贴色块");
                                CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                                cfcBarcode1.DestinationRectangle = new Rectangle(
                                 0,
                                 0,
                                 barcodeImageTemp.Width,
                                 barcodeImageTemp.Height);

                                cfcBarcode1.SourcePoint = Point.Empty;
                                cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                                cfcBarcode1.DestinationImage = barcodeImageTemp;
                                cfcBarcode1.Run(ColorImgBlock);


                                UPTLab("生成条码及文字");

                                #region 打印条码及文字信息
                                Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                                SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                                int recX = ColorImgBlock.Width + 5, recY = -2;
                                string Barcode = "";
                                string nullBar = " ";
                                SizeF sizeF;
                                if (DateTransfer.SelectBarCodeType == 1)
                                {
                                    recX += 20;
                                    //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                    //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                    Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                                }
                                else if (DateTransfer.SelectBarCodeType == 0)
                                {
                                    recX += 20;
                                    int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                    int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                    Barcode = "*" + picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1) + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);

                                }
                                else
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }

                                BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度

                                //色块就有50
                                //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                                if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                                {
                                    //打条码
                                    Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                    processor.Draw3dText(g,
                                                       Barcode,
                                                         rc,
                                                         SpecialEffectsTextStyle.Normal,
                                                         SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                         0, /* horizontal  shadow position */
                                                         0, /* vertical shadow position */
                                                         Color.Black, /* text color, blue */
                                                         Color.White,/* shadow color, black */
                                                         Color.White, /* border color, white */
                                                         DateTransfer.SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o9,
                                                         null);

                                    recX += BARCODEWIDTH;
                                }
                                else
                                {

                                }


                                //写其文字信息

                                recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                                string productName = "";
                                string leftProduct = "";
                                picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                                int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                                if (PIndex > 0)
                                {
                                    productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                    leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex + 1);
                                }
                                else
                                {
                                    productName = picInfo.BasePhotoInfo.PhotoName;
                                    leftProduct = "-";
                                }



                                Rectangle rcFont = new Rectangle(recX - 20, -3, barcodeImageTemp.Width - recX, BARCODEHEIDHT);
                                string text = "";
                                try
                                {
                                    text = GetBarCodeStringByCutsom(picInfo, board);
                                }
                                catch
                                {

                                }
                                processor.Draw3dText(g,
                                                    text,
                                                    rcFont,
                                                    SpecialEffectsTextStyle.Normal,
                                                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                    0, /* horizontal  shadow position */
                                                    0, /* vertical shadow position */
                                                    FontColor,/* text color, blue */
                                                    Color.White,/* shadow color, black */
                                                    Color.White, /* border color, white */
                                                    textFont,
                                                    null);

                                g.Dispose();
                                ColorImgBlock.Dispose();//释放色块的资源
                                #endregion

                                UPTLab("向中间图片mdiImageTemp图贴图片");

                                #region 向中间图片mdiImageTemp图贴图片

                                CombineFastCommand cfcCommand = new CombineFastCommand();
                                Rectangle barCodeRec, picRec;

                                if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左\右边
                                {
                                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                    rcBarcode.Angle = 270 * 100;
                                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                    rcBarcode.Flags = RotateCommandFlags.Resize;
                                    rcBarcode.Run(barcodeImageTemp);

                                    //barCodeRec = new Rectangle(0, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                                    //picRec = new Rectangle(BARCODEHEIDHT, 0, smallPicImage.Width, smallPicImage.Height);

                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                    barCodeRec = new Rectangle(smallPicImage.Width - BARCODEHEIDHT, 0, BARCODEHEIDHT, barcodeImageTemp.Height);

                                }
                                else  //0:条码放在下面
                                {
                                    //barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, BARCODEHEIDHT);
                                    //picRec = new Rectangle(0, BARCODEHEIDHT, smallPicImage.Width, smallPicImage.Height);

                                    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                    barCodeRec = new Rectangle(0, smallPicImage.Height - BARCODEHEIDHT, barcodeImageTemp.Width, BARCODEHEIDHT);
                                }

                                CombineFastCommand cfcBarcode = new CombineFastCommand();
                                cfcBarcode.SourcePoint = Point.Empty;
                                cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                                cfcBarcode.DestinationImage = midImageTmp;


                                //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                                //{
                                //    UPTLab("对条码进行锐化");
                                //    SharpenCommand command = new SharpenCommand();
                                //    command.Sharpness = 950;
                                //    command.Run(barcodeImageTemp);
                                //}

                                UPTLab("贴条码");
                                //贴条码
                                cfcBarcode.DestinationRectangle = barCodeRec;
                                cfcBarcode.Run(barcodeImageTemp);

                                UPTLab("贴图片");
                                //贴图片
                                cfcBarcode.DestinationRectangle = picRec;
                                cfcBarcode.Run(smallPicImage);

                                barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片

                            }
                            else
                            {

                                //向中间图片上贴图片
                                CombineFastCommand cfcCommand = new CombineFastCommand();
                                cfcCommand.DestinationRectangle = new Rectangle(
                                                                                   0,
                                                                                   0,
                                                                                   smallPicImage.Width,
                                                                                   smallPicImage.Height);
                                cfcCommand.SourcePoint = Point.Empty;
                                cfcCommand.DestinationImage = midImageTmp;
                                cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                                cfcCommand.Run(smallPicImage);
                            }
                        }
                                #endregion

                        UPTLab("给中间图画边框");
                        #region //给中间图画边框
                        if (DateTransfer.IsPrintLine)
                        {
                            Graphics g2 = null;
                            try
                            {
                                SpecialEffectsProcessor processor2 = new SpecialEffectsProcessor();
                                g2 = midImageTmp.CreateGdiPlusGraphics().Graphics;

                                Rectangle rcShape2 = new Rectangle(0, 0, midImageTmp.ImageWidth, midImageTmp.ImageHeight);


                                processor2.Draw3dShape(g2,
                                                         SpecialEffectsShape.Rectangle, /* star shape */
                                                         rcShape2,  /* destination rectangle */
                                                         Color.Black, /* background color, blue */
                                                         null, /* use this to place an image in the background */
                                                         rcShape2, /* display background rectangle */
                                                         SpecialEffectsBackStyle.TranslucentTiledImage, /* style flags for 3D shape */
                                                         Color.Black, /* foreground color, red */
                                                         SpecialEffectsFillStyle.Transparent, /* foreground style */
                                                         Color.Black, /* border color, red */
                                                         SpecialEffectsBorderStyle.Solid, /* border style */
                                                         2, /* border width */
                                                         Color.Black, /* inner band highlight color, white */
                                                         Color.Black, /* inner band shadow color */
                                                         SpecialEffectsInnerStyle.None, /* inner band style */
                                                         0, /* inner band width */
                                                         Color.Black, /* outer band highlight color, RED */
                                                         Color.Black, /* outer band shadow color */
                                                         SpecialEffectsOuterStyle.None,/* outer band style */
                                                         1, /* outer band width */
                                                         0, /* horizontal shadow position */
                                                         0, /* vertical shadow position */
                                                         Color.Black, /* shadow color, black */
                                                         null);    /* no region handle */

                            }
                            catch (Exception Boardex)//如果添加边框出错就不添加
                            {
                                WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.BasePhotoInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                            }
                            finally
                            {
                                if (g2 != null)
                                {
                                    g2.Dispose();
                                }
                            }
                        }
                        #endregion

                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }

                        UPTLab("正在旋转小图...");
                        if (midImageTmp.Width >= 15000 || midImageTmp.Height >= 15000)//大于这个尺寸就用PS进行旋转
                        {
                            try
                            {
                                if (File.Exists(Application.StartupPath + "\\temHT.jpg"))
                                {
                                    File.Delete(Application.StartupPath + "\\temHT.jpg");
                                }
                                if (File.Exists(Application.StartupPath + "\\temH.jpg"))
                                {
                                    File.Delete(Application.StartupPath + "\\temH.jpg");
                                }
                            }
                            catch { }
                            midImageTmp.XResolution = midImageTmp.YResolution = board.BoardBaseInfo.DPI;

                            codecs.Save(midImageTmp, Application.StartupPath + "\\temHT.jpg", RasterImageFormat.Jpeg, 24);

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //myClass.DoRotate(Application.StartupPath + "\\temHT.jpg", Application.StartupPath + "\\temH.jpg", true, 90);

                            psApp.RotatePic(Application.StartupPath + "\\temHT.jpg", Application.StartupPath + "\\temH.jpg", 90);

                            midImageTmp = codecs.Load(Application.StartupPath + "\\temH.jpg");
                        }
                        else
                        {
                            RotateCommand rcTemp = new RotateCommand();//旋转条码图片               
                            rcTemp.Angle = 90 * 100;

                            rcTemp.Flags = RotateCommandFlags.Resize;
                            rcTemp.Run(midImageTmp);
                        }

                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                                                                        pointY,//在大图上的坐标
                                                                        pointX,
                                                                        midImageTmp.Width,//长和宽
                                                                        midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (board.IsTransverse)//自动裁切模式IsTransverse 改为是否使用裁切选择项目
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();

                            photoP.X = pointY;
                            photoP.Y = pointX;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;
                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.PhotoS.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.BasePhotoInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.BasePhotoInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;

                int qipanHeight = Convert.ToInt32(0.5 / 2.54 * board.BoardBaseInfo.DPI);

                if (DateTransfer.CutMinPhotoNum == 0)
                {
                    //不处理
                }
                else
                {
                    if (board.PhotoS.Count <= DateTransfer.CutMinPhotoNum)
                    {
                        DateTransfer.IsAutoCut = false;
                    }
                    else
                    {
                        //不处理
                    }
                }
                if (DateTransfer.IsAutoCut)//自动裁切模式要替换最终destImage
                {
                    UPTLab("创建自动裁切信息");
                    ///创建大板的条码信息
                    //RasterImage destTempImage = destImage;//先将名称替换掉
                    RasterImage boardPointInfoImage = new RasterImage(
                                                        RasterMemoryFlags.Conventional,
                                                        destImage.Height,
                                                        qipanHeight,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//条码信息色块中间白板图

                    RasterImage destTempImage = new RasterImage(RasterMemoryFlags.Conventional,
                                                        destImage.Width,
                                                        destImage.Height + qipanHeight,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//);
                    ///填充颜色
                    FillCommand fcommandW = new FillCommand();
                    fcommandW.Color = new RasterColor(255, 255, 255);
                    fcommandW.Run(destTempImage);
                    fcommandW.Run(boardPointInfoImage);
                    destTempImage.XResolution = destImage.XResolution;

                    destTempImage.YResolution = destImage.YResolution;
                    //条码文字信息
                    //Graphics g = barcodeImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                    //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    int recCurrX = XExcursion, recCurrY = 0;




                    //#region
                    ////打定位色块第一组
                    //#region///棋盘定位
                    RasterImage ColorImgBlockWhite = CreateColorBlock(Color.Black.R, Color.Black.G, Color.Black.B);
                    RasterImage ColorImgBlockBlack = CreateColorBlock(Color.Black.R, Color.Black.G, Color.Black.B);



                    UPTLab("粘贴色块");

                    #region //Old色块
                    ////粘贴色块
                    ////第一组色块中心距离原点30+偏移
                    //int currRecy = 0;
                    //for (int icolor = 0; icolor <= 15; icolor++)
                    //{
                    //    if (icolor % 2 == 0)
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy,
                    //         10,
                    //         10,
                    //         10);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockBlack);
                    //    }
                    //    else
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy,
                    //         20,
                    //         10,
                    //         10);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockWhite);
                    //    }
                    //    currRecy += 10;
                    //}

                    //int currRecy2 = destImage.Width - 540;//最后一个棋盘交叉距离版右边部20cm
                    //for (int icolor = 0; icolor < 15; icolor++)
                    //{
                    //    if (icolor % 2 == 0)
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy2,
                    //         10,
                    //         10,
                    //         10);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockBlack);
                    //    }
                    //    else
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy2,
                    //         20,
                    //         10,
                    //         10);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockWhite);
                    //    }
                    //    currRecy2 += 10;
                    //}
                    #endregion



                    #region///文字 条码信息
                    ////条码文字
                    //SizeF sizeF = gFont.MeasureString("*" + board.BoardBaseInfo.BoardId.ToString() + "*", textBarFont);

                    ////打条码
                    //Rectangle rcBarcode = new Rectangle(300, 0, 525, 25);//在200打75宽 50高的条码

                    //Graphics gb = boardPointInfoImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字

                    //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    //processor.Draw3dText(gb,
                    //                   "*" + board.BoardBaseInfo.BoardId + "*",
                    //                     rcBarcode,
                    //                     SpecialEffectsTextStyle.Normal,
                    //                     SpecialEffectsTextAlignmentFlags.HorizontalCenter | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                    //                     0, /* horizontal  shadow position */
                    //                     0, /* vertical shadow position */
                    //                     Color.Black, /* text color, blue */
                    //                     Color.White,/* shadow color, black */
                    //                     Color.White, /* border color, white */
                    //                     textBarFont,
                    //                     null);

                    ////粘贴色块

                    ////打印文字及其区域

                    //Rectangle rcFont = new Rectangle(1500, 0, 500, 30);

                    //string barStr = board.BoardBaseInfo.BoardId.ToString();


                    //processor.Draw3dText(gb,
                    //                    barStr,
                    //                    rcFont,
                    //                    SpecialEffectsTextStyle.Normal,
                    //                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.Top,
                    //                    0, /* horizontal  shadow position */
                    //                    0, /* vertical shadow position */
                    //                    Color.Black,/* text color, blue */
                    //                    Color.White,/* shadow color, black */
                    //                    Color.White, /* border color, white */
                    //                    textFont,
                    //                    null);

                    //gb.Dispose();
                    #endregion
                    //ClassVectorPointClass cvpc = new ClassVectorPointClass();
                    if (File.Exists(Application.StartupPath + "\\temBar.bmp"))
                    {
                        File.Delete(Application.StartupPath + "\\temBar.bmp");
                    }
                    string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");

                    //var p1 = mai.CreateMarkPictureToFile(Convert.ToInt32(boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    //Image img = Microsoft.VisualBasic.Compatibility.VB6.Support.IPictureToImage(p1);
                    //RasterImage smallTop = new RasterImage(img);

                    CombineFastCommand cfctop = new CombineFastCommand();
                    cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                    cfctop.SourcePoint = Point.Empty;
                    cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(smallTop);
                    cfctop.DestinationRectangle = new Rectangle(0, qipanHeight, destImage.Width, destImage.Height);
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(destImage);
                    destImage = destTempImage;//重新赋值

                    //写入文件 
                    StringBuilder sbWriter = new StringBuilder();
                    //sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.DPI);
                    sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.PrinterName.Trim());
                    foreach (PhotoPoint pp in listPhotoInfoForCut)
                    {
                        string mmX = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                        string mmy = (((double)pp.Y / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                        string mmWidth = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                        string mmheight = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                        string dxfFlag = "DXF";
                        string strWriter = "";
                        if (pp.DXFContent == null)
                        {
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                        }
                        else
                        {
                            string angleStr = pp.Angle.ToString();
                            string wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                            string hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                            string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", ";");
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                        hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                        }
                        sbWriter.AppendLine(strWriter);

                    }
                    string FileName = _curCutFileFullPath;
                    if (File.Exists(FileName))
                    {
                        File.Delete(FileName);
                    }
                    WrtieTextEn(sbWriter, FileName);
                    EncryptionAndSave(board.BoardBaseInfo.BoardId, sbWriter);
                }
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;

                if (board.AddSharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    SharpenCommand command = new SharpenCommand();
                    command.Sharpness = board.AddSharpen;
                    command.Run(destImage);
                }

                UPTLab("正在保存大图...");
                bool isNeedAddIcc = false;
                if (!string.IsNullOrEmpty(board.IccPath))
                {
                    if (board.IccPath.EndsWith(".icc", true, null) || board.IccPath.EndsWith(".icm", true, null))
                    {
                        if (File.Exists(board.IccPath))
                        {
                            isNeedAddIcc = true;//只有当ICCPATH不为空字符串，则是以。ICC、ICM结尾的，且文件存在的才加ICC
                        }
                    }

                }
                if (DateTransfer.AddIccByType == 0)
                {
                    isNeedAddIcc = false;
                }
                if (isNeedAddIcc)//需要加载ICC
                {
                    if (DateTransfer.AddIccByType == 1)//需要用PS加载ICC
                    {
                        //先保存到本地,等加载好ICC时存到网络路径                  
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }

                        //再调用PS加载ICC
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                            }
                            catch { }
                            string strPicFormat = "JPEG";
                            //string strInputIcc = "ColorMatch RGB";
                            string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            if (board.IsTransverse)//竖向的就转90
                                intRatate = -90;
                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);

                            
                            string strResult =psApp.AddICC(iccName, strTempPath, destFileName);

                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件错误" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                            }
                            catch { }
                        }
                    }
                    else if (DateTransfer.AddIccByType == 2)
                    {
                        string tamPath = Environment.GetEnvironmentVariable("TEMP");
                        strTempPath = tamPath + "\\abc.jpg";
                        string iccPath = tamPath + board.IccPath.Substring(board.IccPath.LastIndexOf("\\"));
                        string loadediccPath = tamPath + "\\def.jpg";
                        string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        string fromTempICC = tamPath + "\\sRGB Color Space Profile.icm";
                        string exePath = Application.StartupPath + "\\IccProcessEXE.exe";
                        if (File.Exists(strTempPath))
                        {
                            File.Delete(strTempPath);
                        }
                        if (File.Exists(loadediccPath))
                        {
                            File.Delete(loadediccPath);
                        }
                        if (!File.Exists(iccPath))
                        {
                            File.Copy(board.IccPath, iccPath);
                        }
                        if (!File.Exists(fromTempICC))
                        {
                            File.Copy(FromIcc, fromTempICC);
                        }
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }
                        string iccFile = "";
                        //string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        try
                        {
                            UPTLab("正在加载ICC:" + board.IccPath);

                            using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                            {
                                pExecuteEXE.StartInfo.FileName = exePath;
                                //pExecuteEXE.StartInfo.Arguments = @"c:\1410.jpg,c:\sRGB Color Space Profile.icm,c:\efg1.jpg,c:\dnp100305-003.icm,95";
                                //pExecuteEXE.StartInfo.Arguments = strTempPath + "," + fromTempICC + "," + loadediccPath + "," + iccPath + "," + 95;
                                pExecuteEXE.StartInfo.Arguments = strTempPath + "," + doubleQM + fromTempICC + doubleQM + "," + loadediccPath + "," + doubleQM + iccPath + doubleQM + "," + 95;
                                pExecuteEXE.Start();
                                pExecuteEXE.WaitForExit();
                            }

                            //iccFile = iccLoad.IccProcess(strTempPath, fromTempICC, loadediccPath, iccPath,"100");
                            //if (!loadediccPath.Equals(iccFile))
                            //{
                            //    UPTLab("加载ICC文件错误:");
                            //    throw new Exception("加载ICC文件错误");

                            //}
                            //else
                            //{
                            //    File.Copy(loadediccPath, destFileName);
                            //}
                            if (File.Exists(loadediccPath))
                            {
                                try
                                {
                                    File.Copy(loadediccPath, destFileName, true);
                                }
                                catch (Exception ex)
                                {
                                    UPTLab("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有路径访问权限");
                                    throw new Exception("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有改路径访问权限");

                                }
                            }
                        }
                        catch
                        {
                        }

                    }
                    else//用LEADTOOLS加载ICC
                    {
                        //处理旋转的问题
                        //if (board.IsTransverse)//竖向的就转90
                        //{
                        //    UPTLab("正在竖向旋转90度...");
                        //    if (destImage.Width >= 18898 || destImage.Height >= 18898)//大于这个尺寸就用PS进行旋转
                        //    {
                        //        try
                        //        {
                        //            File.Delete(Application.StartupPath + "\\tem.jpg");
                        //        }
                        //        catch { }

                        //        codecs.Save(destImage, Application.StartupPath + "\\temBig.jpg", RasterImageFormat.Jpeg, 24);

                        //        PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                        //        myClass.DoRotate(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", true, 90);
                        //        destImage = codecs.Load(Application.StartupPath + "\\tem.jpg");
                        //        File.Delete(Application.StartupPath + "\\temBig.jpg");
                        //    }
                        //    else
                        //    {
                        //        RotateCommand rc = new RotateCommand();
                        //        rc.Angle = 90 * 100;
                        //        rc.FillColor = new RasterColor(255, 255, 255);
                        //        rc.Flags = RotateCommandFlags.Resize;
                        //        rc.Run(destImage);
                        //    }
                        //}

                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                                break;
                        }

                        try
                        {
                            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                        }
                        catch (Exception ef)
                        {
                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }
                    }
                }
                else//不需要加载ICC，则直接保存
                {

                    //处理旋转的问题
                    //if (board.IsTransverse)//竖向的就转90
                    //{
                    //    UPTLab("正在竖向旋转90度...");
                    //    if (destImage.Width >= 18898 || destImage.Height >= 18898)//大于这个尺寸就用PS进行旋转
                    //    {
                    //        try
                    //        {
                    //            File.Delete(Application.StartupPath + "\\tem.jpg");
                    //        }
                    //        catch { }

                    //        codecs.Save(destImage, Application.StartupPath + "\\temBig.jpg", RasterImageFormat.Jpeg, 24);

                    //        PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                    //        myClass.DoRotate(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", true, 90);
                    //        destImage = codecs.Load(Application.StartupPath + "\\tem.jpg");
                    //        File.Delete(Application.StartupPath + "\\temBig.jpg");
                    //    }
                    //    else
                    //    {
                    //        RotateCommand rc = new RotateCommand();
                    //        rc.Angle = 90 * 100;
                    //        rc.FillColor = new RasterColor(255, 255, 255);
                    //        rc.Flags = RotateCommandFlags.Resize;
                    //        rc.Run(destImage);
                    //    }
                    //}

                    switch (PicFormat)
                    {
                        case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }
                }

                #region //写入ICC文件

                //UPTLab("正在加载ICC文件..." + board.IccPath);
                //if (!string.IsNullOrEmpty(board.IccPath))
                //{
                //    if (DateTransfer.AddIccByPs)//需要用PS加载ICC
                //    {
                //        try
                //        {
                //            //iCC的名称，需要与PS中的一致
                //            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                //            iccName = iccName.Substring(0, iccName.IndexOf("."));
                //            try
                //            {
                //                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                //            }
                //            catch { }
                //            string strPicFormat = "JPEG";
                //            string strInputIcc = "ColorMatch RGB";
                //            int intRatate = 0;
                //            if (board.IsTransverse)//竖向的就转90
                //                intRatate = -90;
                //            PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                //            //MessageBox.Show("请查看"+strTempPath+"是否有图片");
                //            string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);

                //            if (strResult == destFileName)
                //            {
                //                //MessageBox.Show("保存到" + destFileName);
                //                UPTLab("成功加载ICC文件!");
                //            }
                //            else
                //            {
                //                //MessageBox.Show("加载失败了！");
                //                //加载ICC失败
                //                UPTLab("加载ICC文件失败!" + strResult);
                //            }
                //        }
                //        catch (Exception ex)
                //        {
                //            throw new Exception("加载ICC文件错误" + ex.Message);
                //        }
                //        finally
                //        {
                //            try
                //            {
                //                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                //            }
                //            catch { }
                //        }
                //    }
                //    else   //用LEADTOOLS加载ICC
                //    {
                //        try
                //        {
                //            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                //            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                //        }
                //        catch (Exception ef)
                //        {
                //            UPTLab("加载ICC文件错误:" + ef.Message);
                //            throw new Exception("加载ICC文件错误" + ef.Message);
                //        }
                //    }
                //}
                #endregion


                destImage.Dispose();


                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                board.BoardBaseInfo.PicPath = destFileName;
                _mainBLL.MakeBigPicSusscess(board);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString() + "张");


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                WriteLogForCheck.WriteLogFile(DateTime.Now + ":" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
            }
            finally
            {
                errText = "";
            }
        }
        /// <summary>
        /// 竖向合成 图像旋转竖向是取反
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2(BoardInfo_MakeBigPic board)
        {
            int XExcursion = 0;//X坐标偏移量
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            //int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            //int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            int boardPixWidth = board.BoardBaseInfo.Height; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.Length;//大图的高,相素高宽互换

            //XExcursion = boardPixWidth;
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸
            if (DateTransfer.SaveFileType == 1)
            {
                PicFormat = 1;
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            else
            {
                PicFormat = 0;
            }

            DateTransfer.IsAutoCut = board.IsTransverse;

            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {

                RasterCodecs codecs = new RasterCodecs();
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    boardPixWidth,//+1保证最右边的框线可以出来
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                Color backColor = DateTransfer.BackColor;

                FillCommand fcommand = new FillCommand();
                //fcommand.Color = new RasterColor(128, 128, 128);
                fcommand.Color = new RasterColor(backColor);

                fcommand.Run(destImage);

                UPTLab("渲染大图框架成功");
                foreach (var picInfo in board.PhotoS)
                {
                    UPTLab("正在添加小图:" + picInfo.BasePhotoInfo.PhotoId);
                    try
                    {

                        // 根据加急级别以及是否清空等确定字体的颜色
                        if (!File.Exists(picInfo.BasePhotoInfo.PicPath))
                        {
                            throw new Exception("文件未找到:" + picInfo.BasePhotoInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);

                        if (!string.IsNullOrEmpty(DateTransfer.RemarkKeysColor))
                        {
                            FontColor = GetRemarkColor(picInfo.BasePhotoInfo.PicPath);

                        }
                        RasterImage smallPicImage = CreatePicImgV(picInfo, codecs, board);//
                        DrowPicLine(ref smallPicImage, Color.Green);
                        UPTLab("正在合成中间图");
                        RasterImage midImageTmp = CreateMidImgV(picInfo);//带有条码的中间图是竖版中间图
                        //UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)


                        //是否有备注
                        if (picInfo.barCodeStatus != SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode)//有条码
                        {

                            Color backColorBarcode = new Color();
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board, out backColorBarcode);//条码图片的临时图片
                            if (DateTransfer.PhotoRemarkFlag == 0)
                            {

                            }
                            else
                            {
                                double gray = backColorBarcode.R * 0.299 + 0.587 * backColorBarcode.G + 0.114 * backColorBarcode.B;
                                if (gray >= 128)
                                {
                                    FontColor = Color.Black;
                                }
                                else
                                {
                                    FontColor = Color.FromArgb(255, 255, 255);
                                }
                                //FontColor = Color.FromArgb(255-backColorBarcode.R,255-backColorBarcode.G,255-backColorBarcode.B);
                            }
                            //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            RasterImage ColorImgBlock = DateTransfer.PhotoRemarkFlag == 0 ? GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId) : GetColorBlockTextBackcolor(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                            UPTLab("粘贴色块");
                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                             0,
                             0,
                             barcodeImageTemp.Width,
                             barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);


                            UPTLab("生成条码及文字");

                            #region 打印条码及文字信息
                            Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            g.SmoothingMode = SmoothingMode.None;
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            int recX = ColorImgBlock.Width + 5, recY = -2;
                            string Barcode = "";
                            string nullBar = " ";
                            SizeF sizeF;
                            if (DateTransfer.SelectBarCodeType == 1)
                            {
                                recX += 20;
                                //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                            }
                            else if (DateTransfer.SelectBarCodeType == 0)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                //if (IsNum(tempBarcode))
                                //{
                                //    Barcode = "*" + tempBarcode + "*";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                //else
                                //{
                                //    Barcode = "";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                Barcode = "*" + tempBarcode + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o9);

                            }
                            else if (DateTransfer.SelectBarCodeType == 3)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('『');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('』');
                                if (startIndex == -1 || endIndex == -1)
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }
                                else
                                {
                                    string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                    //if (IsNum(tempBarcode))
                                    //{
                                    //    Barcode = "*" + tempBarcode + "*";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    //else
                                    //{
                                    //    Barcode = "";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    Barcode = "*" + tempBarcode + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                                }
                            }

                            else
                            {
                                Barcode = "";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                            }

                            BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度
                            //BARCODEWIDTH = Convert.ToInt16(sizeF.Width / gFont.DpiX * board.BoardBaseInfo.DPI);



                            //色块就有50
                            //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                //g.DrawString (Brushes

                                //processor.Draw3dShape(g, SpecialEffectsShape.Rectangle, rc, Color.White, null, rc, SpecialEffectsBackStyle.Opaque, Color.White, SpecialEffectsFillStyle.Solid, Color.White, SpecialEffectsBorderStyle.Solid, 0, Color.White, Color.White, SpecialEffectsInnerStyle.None, 0, Color.White, Color.White, SpecialEffectsOuterStyle.None, 0, 0, 0, Color.White, null);

                                processor.Draw3dText(g,
                                                    Barcode,
                                                    rc,
                                                    SpecialEffectsTextStyle.Normal,
                                                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                    0, /* horizontal  shadow position */
                                                    0, /* vertical shadow position */
                                                    Color.Black,/* text color, blue */
                                                    Color.White,/* shadow color, black */
                                                    Color.White, /* border color, white */
                                                    textBarFont3o92,
                                                    null);



                                //StringFormat barFormat = new StringFormat();
                                //barFormat.Alignment = StringAlignment.Center;
                                //barFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;
                                //barFormat.LineAlignment = StringAlignment.Center;
                                ////Rectangle rcBarcode = new Rectangle(rc.X, rc.Y, Convert.ToInt16(rc.Width / gFont.DpiX * board.BoardBaseInfo.DPI), Convert.ToInt16(rc.Height / gFont.DpiX * board.BoardBaseInfo.DPI));

                                //Font barF = DateTransfer.SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o92;
                                //g.DrawString(Barcode, barF, new SolidBrush(Color.Black), rc, barFormat);
                                //g.DrawString("123", textFont, new SolidBrush(Color.Black), rc,barFormat);

                                recX += BARCODEWIDTH;
                            }
                            else
                            {

                            }


                            //写其文字信息

                            recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            string productName = "";
                            string leftProduct = "";
                            picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                            int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                            if (PIndex > 0)
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex);
                            }
                            else
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName;
                                leftProduct = "-";
                            }

                            //SpecialEffectsTextAlignmentFlags alignHorizontal = SpecialEffectsTextAlignmentFlags.Left;
                            //if (TextAlignType == 0)
                            //{
                            //    alignHorizontal = SpecialEffectsTextAlignmentFlags.Left;

                            //}
                            //else if (TextAlignType == 1)
                            //{
                            //    alignHorizontal = SpecialEffectsTextAlignmentFlags.Right;
                            //}
                            //else
                            //{
                            //    alignHorizontal = SpecialEffectsTextAlignmentFlags.HorizontalCenter;
                            //}
                            string text = "";
                            try
                            {
                                text = GetBarCodeStringByCutsom(picInfo, board).Trim('\\');
                            }
                            catch
                            {

                            }
                            SizeF sizetextF = gFont.MeasureString(text, textFont);

                            StringFormat textFormat = new StringFormat();
                            textFormat.Alignment = StringAlignment.Near;
                            textFormat.LineAlignment = StringAlignment.Center;
                            textFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;

                            //textFormat.
                            Rectangle rcFont = new Rectangle(recX, 2, barcodeImageTemp.Width - recX, BARCODEHEIDHT);

                            //processor.Draw3dText(g,
                            //                    text,
                            //                    rcFont,
                            //                    SpecialEffectsTextStyle.Normal,
                            //                    alignHorizontal | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                            //                    0, /* horizontal  shadow position */
                            //                    0, /* vertical shadow position */
                            //                    FontColor,/* text color, blue */
                            //                    backColorBarcode,/* shadow color, black */
                            //                    backColorBarcode, /* border color, white */
                            //                    textFont,
                            //                    null);
                            gFont.PageUnit = GraphicsUnit.Pixel;

                            string newText = text;
                            if (DateTransfer.TextAlignType == 0)//左
                            {
                                newText = text;
                            }
                            else if (DateTransfer.TextAlignType == 1)//右对齐
                            {
                                for (int m = 0; m < text.Length; m++)
                                {
                                    newText = text.Substring(m);

                                    SizeF sizenewtextF = gFont.MeasureString(newText, textFont, barcodeImageTemp.Width - recX, textFormat);

                                    if (sizenewtextF.Width <= (barcodeImageTemp.Width - recX) * gFont.DpiX / board.BoardBaseInfo.DPI)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                newText = text;
                                textFormat.Alignment = StringAlignment.Center;
                                textFormat.LineAlignment = StringAlignment.Center;
                            }


                            g.PageUnit = GraphicsUnit.Pixel;
                            g.DrawString(newText, textFont, new SolidBrush(FontColor), rcFont, textFormat);


                            //codecs.Save(barcodeImageTemp, @"c:\\barcodeImageTemp.jpg", RasterImageFormat.Jpeg, 24);

                            g.Dispose();
                            //gFont.Dispose();
                            ColorImgBlock.Dispose();//释放色块的资源
                            #endregion

                            UPTLab("正在粘贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            Rectangle barCodeRec, picRec;

                            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左\右边 实际 出来是上下
                            {
                                //RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                //rcBarcode.Angle = 270 * 100;
                                //rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                //rcBarcode.Flags = RotateCommandFlags.Resize;
                                //rcBarcode.Run(barcodeImageTemp);

                                //barCodeRec = new Rectangle(0, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                                //picRec = new Rectangle(BARCODEHEIDHT, 0, smallPicImage.Width, smallPicImage.Height);

                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                //barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                                barCodeRec = new Rectangle(0, smallPicImage.Height, smallPicImage.Width, BARCODEHEIDHT);
                            }
                            else  //0:条码放在下面
                            {
                                //barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, BARCODEHEIDHT);
                                //picRec = new Rectangle(0, BARCODEHEIDHT, smallPicImage.Width, smallPicImage.Height);
                                RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                rcBarcode.Angle = 270 * 100;
                                rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                rcBarcode.Flags = RotateCommandFlags.Resize;
                                rcBarcode.Run(barcodeImageTemp);
                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIDHT, smallPicImage.Height);
                            }

                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            cfcBarcode.SourcePoint = Point.Empty;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.DestinationImage = midImageTmp;


                            //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                            //{
                            //    //UPTLab("对条码进行锐化");
                            //    //SharpenCommand command = new SharpenCommand();
                            //    //command.Sharpness = 950;
                            //    //command.Run(barcodeImageTemp);
                            //}

                            //UPTLab("贴条码");
                            //贴条码
                            cfcBarcode.DestinationRectangle = barCodeRec;
                            cfcBarcode.Run(barcodeImageTemp);

                            //UPTLab("贴图片");
                            //贴图片
                            cfcBarcode.DestinationRectangle = picRec;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.Run(smallPicImage);

                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                            #endregion

                        }
                        else//无条码
                        {
                            if (DateTransfer.IsPrintBarCodeInPicture)
                            {
                                RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board);//条码图片的临时图片

                                //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                                RasterImage ColorImgBlock = GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                                UPTLab("粘贴色块");
                                CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                                cfcBarcode1.DestinationRectangle = new Rectangle(
                                 0,
                                 0,
                                 barcodeImageTemp.Width,
                                 barcodeImageTemp.Height);

                                cfcBarcode1.SourcePoint = Point.Empty;
                                cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                                cfcBarcode1.DestinationImage = barcodeImageTemp;
                                cfcBarcode1.Run(ColorImgBlock);


                                UPTLab("生成条码及文字");

                                #region 打印条码及文字信息
                                Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                                SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                                int recX = ColorImgBlock.Width + 5, recY = -2;
                                string Barcode = "";
                                string nullBar = " ";
                                SizeF sizeF;
                                if (DateTransfer.SelectBarCodeType == 1)
                                {
                                    recX += 20;
                                    //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                    //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                    Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                                }
                                else if (DateTransfer.SelectBarCodeType == 0)
                                {
                                    recX += 20;
                                    int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                    int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                    Barcode = "*" + picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1) + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);

                                }
                                else
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }

                                BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度

                                //色块就有50
                                //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                                if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                                {
                                    //打条码
                                    Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                    processor.Draw3dText(g,
                                                       Barcode,
                                                         rc,
                                                         SpecialEffectsTextStyle.Normal,
                                                         SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                         0, /* horizontal  shadow position */
                                                         0, /* vertical shadow position */
                                                         Color.Black, /* text color, blue */
                                                         Color.White,/* shadow color, black */
                                                         Color.White, /* border color, white */
                                                         DateTransfer.SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o9,
                                                         null);

                                    recX += BARCODEWIDTH;
                                }
                                else
                                {

                                }


                                //写其文字信息

                                recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                                string productName = "";
                                string leftProduct = "";
                                picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                                int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                                if (PIndex > 0)
                                {
                                    productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                    leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex + 1);
                                }
                                else
                                {
                                    productName = picInfo.BasePhotoInfo.PhotoName;
                                    leftProduct = "-";
                                }



                                Rectangle rcFont = new Rectangle(recX - 20, -3, barcodeImageTemp.Width - recX, BARCODEHEIDHT);
                                string text = "";
                                try
                                {
                                    text = GetBarCodeStringByCutsom(picInfo, board);
                                }
                                catch
                                {

                                }
                                processor.Draw3dText(g,
                                                    text,
                                                    rcFont,
                                                    SpecialEffectsTextStyle.Normal,
                                                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                    0, /* horizontal  shadow position */
                                                    0, /* vertical shadow position */
                                                    FontColor,/* text color, blue */
                                                    Color.White,/* shadow color, black */
                                                    Color.White, /* border color, white */
                                                    textFont,
                                                    null);

                                g.Dispose();
                                ColorImgBlock.Dispose();//释放色块的资源
                                #endregion

                                UPTLab("向中间图片mdiImageTemp图贴图片");

                                #region 向中间图片mdiImageTemp图贴图片

                                CombineFastCommand cfcCommand = new CombineFastCommand();
                                Rectangle barCodeRec, picRec;

                                //if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左\右边
                                //{
                                //    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                //    rcBarcode.Angle = 270 * 100;
                                //    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                //    rcBarcode.Flags = RotateCommandFlags.Resize;
                                //    rcBarcode.Run(barcodeImageTemp);

                                //    //barCodeRec = new Rectangle(0, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                                //    //picRec = new Rectangle(BARCODEHEIDHT, 0, smallPicImage.Width, smallPicImage.Height);

                                //    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                //    barCodeRec = new Rectangle(smallPicImage.Width - BARCODEHEIDHT, 0, BARCODEHEIDHT, barcodeImageTemp.Height);

                                //}
                                //else  //0:条码放在下面
                                //{
                                //barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, BARCODEHEIDHT);
                                //picRec = new Rectangle(0, BARCODEHEIDHT, smallPicImage.Width, smallPicImage.Height);

                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                barCodeRec = new Rectangle(0, smallPicImage.Height - BARCODEHEIDHT, barcodeImageTemp.Width, BARCODEHEIDHT);
                                //}

                                CombineFastCommand cfcBarcode = new CombineFastCommand();
                                cfcBarcode.SourcePoint = Point.Empty;
                                cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                                cfcBarcode.DestinationImage = midImageTmp;


                                //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                                //{
                                //    UPTLab("对条码进行锐化");
                                //    SharpenCommand command = new SharpenCommand();
                                //    command.Sharpness = 950;
                                //    command.Run(barcodeImageTemp);
                                //}
                                UPTLab("贴图片");
                                //贴图片
                                cfcBarcode.DestinationRectangle = picRec;
                                cfcBarcode.Run(smallPicImage);
                                UPTLab("贴条码");
                                //贴条码
                                cfcBarcode.DestinationRectangle = barCodeRec;
                                cfcBarcode.Run(barcodeImageTemp);



                                barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片

                            }
                            else
                            {
                                //向中间图片上贴图片
                                CombineFastCommand cfcCommand = new CombineFastCommand();
                                cfcCommand.DestinationRectangle = new Rectangle(
                                                                                   0,
                                                                                   0,
                                                                                   smallPicImage.Width,
                                                                                   smallPicImage.Height);
                                cfcCommand.SourcePoint = Point.Empty;
                                cfcCommand.DestinationImage = midImageTmp;
                                cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                                cfcCommand.Run(smallPicImage);
                            }
                        }
                                #endregion

                        UPTLab("正在绘制中间图边框");
                        #region //给中间图画边框
                        if (DateTransfer.IsPrintLine)
                        {
                            Graphics g2 = null;
                            try
                            {
                                //SpecialEffectsProcessor processor2 = new SpecialEffectsProcessor();
                                //g2 = midImageTmp.CreateGdiPlusGraphics().Graphics;

                                //Rectangle rcShape2 = new Rectangle(0, 0, midImageTmp.ImageWidth, midImageTmp.ImageHeight);


                                //processor2.Draw3dShape(g2,
                                //                         SpecialEffectsShape.Rectangle, /* star shape */
                                //                         rcShape2,  /* destination rectangle */
                                //                         Color.Black, /* background color, blue */
                                //                         null, /* use this to place an image in the background */
                                //                         rcShape2, /* display background rectangle */
                                //                         SpecialEffectsBackStyle.TranslucentTiledImage, /* style flags for 3D shape */
                                //                         Color.Black, /* foreground color, red */
                                //                         SpecialEffectsFillStyle.Transparent, /* foreground style */
                                //                         Color.Black, /* border color, red */
                                //                         SpecialEffectsBorderStyle.Solid, /* border style */
                                //                         BoardLineWidth, /* border width */
                                //                         Color.Black, /* inner band highlight color, white */
                                //                         Color.Black, /* inner band shadow color */
                                //                         SpecialEffectsInnerStyle.None, /* inner band style */
                                //                         0, /* inner band width */
                                //                         Color.Black, /* outer band highlight color, RED */
                                //                         Color.Black, /* outer band shadow color */
                                //                         SpecialEffectsOuterStyle.None,/* outer band style */
                                //                         0, /* outer band width */
                                //                         0, /* horizontal shadow position */
                                //                         0, /* vertical shadow position */
                                //                         Color.Black, /* shadow color, black */
                                //                         null);    /* no region handle */
                                DrowBordLine(ref midImageTmp);

                            }
                            catch (Exception Boardex)//如果添加边框出错就不添加
                            {
                                WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.BasePhotoInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                                DrowBordLine(ref midImageTmp);

                            }
                            finally
                            {
                                if (g2 != null)
                                {
                                    g2.Dispose();
                                }
                            }
                        }
                        #endregion
                        UPTLab("正在粘贴图片:ID" + picInfo.BasePhotoInfo.PhotoId + ",照片" + picInfo.BasePhotoInfo.PicPath);
                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }



                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                                                                        pointY,//在大图上的坐标
                                                                        pointX,
                                                                        midImageTmp.Width,//长和宽
                                                                        midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (board.IsTransverse)//自动裁切模式IsTransverse 改为是否使用裁切选择项目
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();

                            photoP.X = pointY;
                            photoP.Y = pointX;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;

                            if (picInfo.IsWhirl)
                            {
                                photoP.Angle = 0;
                            }
                            else
                            {
                                photoP.Angle = 90;
                            }
                            //计算DXF宽高
                            //SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.DxfContent);
                            //DxfObjecctInfo mindxfObjecctInfo =
                            //    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                            //DxfObjecctInfo maxdxfObjecctInfo =
                            //  SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                            //DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                            //DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                            //photoP.DXFWidth = maxPointer.X - minPointer.X;
                            //photoP.DXFHeigth = maxPointer.Y - minPointer.Y;

                            if (!string.IsNullOrEmpty(picInfo.BasePhotoInfo.DXFFilePath))
                            {
                                SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.BasePhotoInfo.DXFContent);
                                DxfObjecctInfo mindxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                                DxfObjecctInfo maxdxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                                DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                                DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                                photoP.DXFWidth = maxPointer.X - minPointer.X;
                                photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                                photoP.DXFContent = picInfo.DxfContent;
                            }
                            else
                            {
                                photoP.DXFWidth = 0;
                                photoP.DXFHeigth = 0;
                                photoP.DXFContent = null;
                            }

                            photoP.DXFContent = picInfo.DxfContent;
                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.PhotoS.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.BasePhotoInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.BasePhotoInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;

                int qipanHeight = Convert.ToInt32(0.5 / 2.54 * board.BoardBaseInfo.DPI);

                if (DateTransfer.CutMinPhotoNum == 0)
                {
                    //不处理
                }
                else
                {
                    if (board.PhotoS.Count <= DateTransfer.CutMinPhotoNum)
                    {
                        DateTransfer.IsAutoCut = false;
                    }
                    else
                    {
                        //不处理
                    }
                }
                if (DateTransfer.IsAutoCut)//自动裁切模式要替换最终destImage
                {
                    UPTLab("创建自动裁切信息");
                    ///创建大板的条码信息
                    //RasterImage destTempImage = destImage;//先将名称替换掉

                    string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                    qipanHeight = smallTop.Height;
                    RasterImage boardPointInfoImage = new RasterImage(
                                                        RasterMemoryFlags.Conventional,
                                                        destImage.Height,
                                                        qipanHeight,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//条码信息色块中间白板图

                    RasterImage destTempImage = new RasterImage(RasterMemoryFlags.Conventional,
                                                        destImage.Width,
                                                        destImage.Height + qipanHeight,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//);
                    ///填充颜色
                    FillCommand fcommandW = new FillCommand();
                    fcommandW.Color = new RasterColor(255, 255, 255);
                    fcommandW.Run(destTempImage);
                    fcommandW.Run(boardPointInfoImage);
                    destTempImage.XResolution = destImage.XResolution;

                    destTempImage.YResolution = destImage.YResolution;
                    //条码文字信息
                    //Graphics g = barcodeImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                    //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    int recCurrX = XExcursion, recCurrY = 0;




                    //#region
                    ////打定位色块第一组
                    //#region///棋盘定位
                    RasterImage ColorImgBlockWhite = CreateColorBlock(Color.Black.R, Color.Black.G, Color.Black.B);
                    RasterImage ColorImgBlockBlack = CreateColorBlock(Color.Black.R, Color.Black.G, Color.Black.B);



                    UPTLab("粘贴色块");

                    #region //Old色块
                    ////粘贴色块
                    ////第一组色块中心距离原点30+偏移
                    //int currRecy = 0;
                    //for (int icolor = 0; icolor <= 15; icolor++)
                    //{
                    //    if (icolor % 2 == 0)
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy,
                    //         10,
                    //         10,
                    //         10);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockBlack);
                    //    }
                    //    else
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy,
                    //         20,
                    //         10,
                    //         10);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockWhite);
                    //    }
                    //    currRecy += 10;
                    //}

                    //int currRecy2 = destImage.Width - 540;//最后一个棋盘交叉距离版右边部20cm
                    //for (int icolor = 0; icolor < 15; icolor++)
                    //{
                    //    if (icolor % 2 == 0)
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy2,
                    //         10,
                    //         10,
                    //         10);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockBlack);
                    //    }
                    //    else
                    //    {
                    //        CombineFastCommand cfcColor11 = new CombineFastCommand();
                    //        cfcColor11.DestinationRectangle = new Rectangle(
                    //         currRecy2,
                    //         20,
                    //         10,
                    //         10);

                    //        cfcColor11.SourcePoint = Point.Empty;
                    //        cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                    //        cfcColor11.DestinationImage = boardPointInfoImage;
                    //        cfcColor11.Run(ColorImgBlockWhite);
                    //    }
                    //    currRecy2 += 10;
                    //}
                    #endregion



                    #region///文字 条码信息
                    ////条码文字
                    //SizeF sizeF = gFont.MeasureString("*" + board.BoardBaseInfo.BoardId.ToString() + "*", textBarFont);

                    ////打条码
                    //Rectangle rcBarcode = new Rectangle(300, 0, 525, 25);//在200打75宽 50高的条码

                    //Graphics gb = boardPointInfoImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字

                    //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    //processor.Draw3dText(gb,
                    //                   "*" + board.BoardBaseInfo.BoardId + "*",
                    //                     rcBarcode,
                    //                     SpecialEffectsTextStyle.Normal,
                    //                     SpecialEffectsTextAlignmentFlags.HorizontalCenter | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                    //                     0, /* horizontal  shadow position */
                    //                     0, /* vertical shadow position */
                    //                     Color.Black, /* text color, blue */
                    //                     Color.White,/* shadow color, black */
                    //                     Color.White, /* border color, white */
                    //                     textBarFont,
                    //                     null);

                    ////粘贴色块

                    ////打印文字及其区域

                    //Rectangle rcFont = new Rectangle(1500, 0, 500, 30);

                    //string barStr = board.BoardBaseInfo.BoardId.ToString();


                    //processor.Draw3dText(gb,
                    //                    barStr,
                    //                    rcFont,
                    //                    SpecialEffectsTextStyle.Normal,
                    //                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.Top,
                    //                    0, /* horizontal  shadow position */
                    //                    0, /* vertical shadow position */
                    //                    Color.Black,/* text color, blue */
                    //                    Color.White,/* shadow color, black */
                    //                    Color.White, /* border color, white */
                    //                    textFont,
                    //                    null);

                    //gb.Dispose();
                    #endregion
                    //ClassVectorPointClass cvpc = new ClassVectorPointClass();
                    if (File.Exists(Application.StartupPath + "\\temBar.bmp"))
                    {
                        File.Delete(Application.StartupPath + "\\temBar.bmp");
                    }

                    //var p1 = mai.CreateMarkPictureToFile(Convert.ToInt32(boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    //Image img = Microsoft.VisualBasic.Compatibility.VB6.Support.IPictureToImage(p1);
                    //RasterImage smallTop = new RasterImage(img);

                    CombineFastCommand cfctop = new CombineFastCommand();
                    cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                    cfctop.SourcePoint = Point.Empty;
                    cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(smallTop);
                    cfctop.DestinationRectangle = new Rectangle(0, qipanHeight, destImage.Width, destImage.Height);
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(destImage);
                    destImage = destTempImage;//重新赋值

                    //写入文件 
                    StringBuilder sbWriter = new StringBuilder();
                    //sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.DPI);
                    sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.PrinterName.Trim());
                    foreach (PhotoPoint pp in listPhotoInfoForCut)
                    {
                        string mmX = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                        string mmy = (((double)pp.Y / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                        string mmWidth = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                        string mmheight = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                        string dxfFlag = "DXF";
                        string strWriter = "";
                        if (pp.DXFContent == null)
                        {
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                        }
                        else
                        {
                            string angleStr = pp.Angle.ToString();
                            string wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                            string hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                            string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", ";");
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                        hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                        }
                        sbWriter.AppendLine(strWriter);

                    }
                    string FileName = _curCutFileFullPath;
                    if (File.Exists(FileName))
                    {
                        File.Delete(FileName);
                    }
                    WrtieTextEn(sbWriter, FileName);
                    EncryptionAndSave(board.BoardBaseInfo.BoardId, sbWriter);
                }
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;

                if (board.AddSharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    SharpenCommand command = new SharpenCommand();
                    command.Sharpness = board.AddSharpen;
                    command.Run(destImage);
                }

                UPTLab("正在保存大图...");
                bool isNeedAddIcc = false;
                if (!string.IsNullOrEmpty(board.IccPath))
                {
                    if (board.IccPath.EndsWith(".icc") || board.IccPath.EndsWith(".icm"))
                    {
                        if (File.Exists(board.IccPath))
                        {
                            isNeedAddIcc = true;//只有当ICCPATH不为空字符串，则是以。ICC、ICM结尾的，且文件存在的才加ICC
                        }
                    }

                }
                if (DateTransfer.AddIccByType == 0)
                {
                    isNeedAddIcc = false;
                }
                if (isNeedAddIcc)//需要加载ICC
                {
                    if (DateTransfer.AddIccByType == 1)//需要用PS加载ICC
                    {
                        //先保存到本地,等加载好ICC时存到网络路径                  
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }

                        //再调用PS加载ICC
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                            }
                            catch { }
                            string strPicFormat = "JPEG";
                            //string strInputIcc = "ColorMatch RGB";
                            string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            if (board.IsTransverse)//竖向的就转90
                                intRatate = -90;
                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);
                                                        
                            string strResult = psApp.AddICC(iccName, strTempPath, destFileName);


                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件错误" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                            }
                            catch { }
                        }
                    }
                    else if (DateTransfer.AddIccByType == 2)
                    {
                        //调用IccProcessEXE 加载ICC

                        string tamPath = Environment.GetEnvironmentVariable("TEMP");
                        strTempPath = tamPath + "\\abc.jpg";
                        string iccPath = tamPath + board.IccPath.Substring(board.IccPath.LastIndexOf("\\"));
                        string loadediccPath = tamPath + "\\def.jpg";
                        string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        string fromTempICC = tamPath + "\\sRGB Color Space Profile.icm";
                        string exePath = Application.StartupPath + "\\IccProcessEXE.exe";
                        if (File.Exists(strTempPath))
                        {
                            File.Delete(strTempPath);
                        }
                        if (File.Exists(loadediccPath))
                        {
                            File.Delete(loadediccPath);
                        }
                        if (!File.Exists(iccPath))
                        {
                            File.Copy(board.IccPath, iccPath);
                        }
                        if (!File.Exists(fromTempICC))
                        {
                            File.Copy(FromIcc, fromTempICC);
                        }
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }
                        string iccFile = "";
                        //string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        try
                        {
                            UPTLab("正在加载ICC:" + board.IccPath);

                            using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                            {
                                pExecuteEXE.StartInfo.FileName = exePath;
                                //pExecuteEXE.StartInfo.Arguments = @"c:\1410.jpg,c:\sRGB Color Space Profile.icm,c:\efg1.jpg,c:\dnp100305-003.icm,95";
                                //pExecuteEXE.StartInfo.Arguments = strTempPath + "," + fromTempICC + "," + loadediccPath + "," + iccPath + "," + 95;
                                pExecuteEXE.StartInfo.Arguments = strTempPath + "," + doubleQM + fromTempICC + doubleQM + "," + loadediccPath + "," + doubleQM + iccPath + doubleQM + "," + 95;
                                pExecuteEXE.Start();
                                pExecuteEXE.WaitForExit();
                            }

                            //iccFile = iccLoad.IccProcess(strTempPath, fromTempICC, loadediccPath, iccPath,"100");
                            //if (!loadediccPath.Equals(iccFile))
                            //{
                            //    UPTLab("加载ICC文件错误:");
                            //    throw new Exception("加载ICC文件错误");

                            //}
                            //else
                            //{
                            //    File.Copy(loadediccPath, destFileName);
                            //}
                            if (File.Exists(loadediccPath))
                            {
                                try
                                {
                                    File.Copy(loadediccPath, destFileName, true);
                                }
                                catch (Exception ex)
                                {
                                    UPTLab("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有路径访问权限");
                                    throw new Exception("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有改路径访问权限");

                                }
                            }
                        }
                        catch
                        {
                        }

                    }
                    else if (DateTransfer.AddIccByType == 3)
                    {
                        //LEADTOOLS加载ICC


                        try
                        {

                            //IccProfileExtended iccProfile = new IccProfileExtended();

                            //// load the ICC from an image, by specifying the image's name, and the 1-based page number that contains the ICC. 
                            //// to load the ICC from an Image that is in a stream, put the stream instead of the file name. 
                            //iccProfile.ReadFromImage(@"E:\开单目录\back-wall-ms  山富灯片ok曲线\25.5x17.4x25.tif", 1);

                            //// at this point, the iccProfile object contains the ICC profile that was found in the image, 
                            //// you can use it as you want, but for this example, we will save it in a seperate ICC profile file. 
                            //// generate the profileId. For the time being, it will be filled with 0's 
                            //iccProfile.GenerateProfileId();

                            //// finally generate the new Icc Profile by updating the Data Array 
                            //// and then generating the file 
                            //iccProfile.UpdateDataArray();
                            switch (PicFormat)
                            {
                                case 0: codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Jpeg, 24);
                                    break;
                                case 1:
                                    codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Tif, 24);
                                    break;
                            }
                            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                            //IccProfileExtended iccP=new IccProfileExtended((
                            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                        }
                        catch (Exception ef)
                        {

                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }




                    }
                    else
                    {



                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                                break;
                        }


                    }
                }
                else//不需要加载ICC，则直接保存
                {


                    switch (PicFormat)
                    {
                        case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }
                }

                #region //写入ICC文件

                //UPTLab("正在加载ICC文件..." + board.IccPath);
                //if (!string.IsNullOrEmpty(board.IccPath))
                //{
                //    if (DateTransfer.AddIccByPs)//需要用PS加载ICC
                //    {
                //        try
                //        {
                //            //iCC的名称，需要与PS中的一致
                //            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                //            iccName = iccName.Substring(0, iccName.IndexOf("."));
                //            try
                //            {
                //                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                //            }
                //            catch { }
                //            string strPicFormat = "JPEG";
                //            string strInputIcc = "ColorMatch RGB";
                //            int intRatate = 0;
                //            if (board.IsTransverse)//竖向的就转90
                //                intRatate = -90;
                //            PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                //            //MessageBox.Show("请查看"+strTempPath+"是否有图片");
                //            string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);

                //            if (strResult == destFileName)
                //            {
                //                //MessageBox.Show("保存到" + destFileName);
                //                UPTLab("成功加载ICC文件!");
                //            }
                //            else
                //            {
                //                //MessageBox.Show("加载失败了！");
                //                //加载ICC失败
                //                UPTLab("加载ICC文件失败!" + strResult);
                //            }
                //        }
                //        catch (Exception ex)
                //        {
                //            throw new Exception("加载ICC文件错误" + ex.Message);
                //        }
                //        finally
                //        {
                //            try
                //            {
                //                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                //            }
                //            catch { }
                //        }
                //    }
                //    else   //用LEADTOOLS加载ICC
                //    {
                //        try
                //        {
                //            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                //            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                //        }
                //        catch (Exception ef)
                //        {
                //            UPTLab("加载ICC文件错误:" + ef.Message);
                //            throw new Exception("加载ICC文件错误" + ef.Message);
                //        }
                //    }
                //}
                #endregion


                destImage.Dispose();


                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                board.BoardBaseInfo.PicPath = destFileName;
                _mainBLL.MakeBigPicSusscess(board);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString());


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //_mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                int boardstatus = _mainBLL.SetBoardStatus2(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                if (boardstatus == 0)
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":无法修改Board状态，如有必要手动删除版" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                else
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                UPTLabBoardErrorList();
            }
            finally
            {
                errText = "";
            }
        }
        /// <summary>
        /// 横向拼版竖向竖向生成并且裁切标记在前面
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2VCutBeforePic(BoardInfo_MakeBigPic board)
        {
            int XExcursion = 0;//X坐标偏移量
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            //int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            //int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            int boardPixWidth = board.BoardBaseInfo.Height; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.Length;//大图的高,相素高宽互换

            //XExcursion = boardPixWidth;
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸
            if (DateTransfer.SaveFileType == 1)
            {
                PicFormat = 1;
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            else
            {
                PicFormat = 0;
            }

            DateTransfer.IsAutoCut = board.IsTransverse;

            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {
                //创建裁切标
                RasterCodecs codecs = new RasterCodecs();
                string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");

                RasterImage smallBottom = codecs.Load(Application.StartupPath + "\\temBar.bmp");   ///       第二定位标记
                int offsetH = smallTop.Height;
                int destHegth = BoardPixHeight + offsetH;
                if (DateTransfer.TwoCutFlag)
                {
                    aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", "", "");
                    smallBottom = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                    destHegth += offsetH;           // 第二定位标记给第二定位标记预留位置
                }
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    boardPixWidth,//+1保证最右边的框线可以出来
                    // BoardPixHeight + offsetH,
                   destHegth,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                Color backColor = DateTransfer.BackColor;

                FillCommand fcommand = new FillCommand();
                //fcommand.Color = new RasterColor(128, 128, 128);
                fcommand.Color = new RasterColor(backColor);

                fcommand.Run(destImage);


                //粘贴裁切标记
                CombineFastCommand cfctop = new CombineFastCommand();
                cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                cfctop.Run(smallTop);
                UPTLab("渲染大图框架成功");
                foreach (var picInfo in board.PhotoS)
                {
                    UPTLab("正在添加小图:" + picInfo.BasePhotoInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上
                        // 根据加急级别以及是否清空等确定字体的颜色
                        if (!File.Exists(picInfo.BasePhotoInfo.PicPath))
                        {
                            throw new Exception("文件未找到:" + picInfo.BasePhotoInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        if (!string.IsNullOrEmpty(DateTransfer.RemarkKeysColor))
                        {
                            FontColor = GetRemarkColor(picInfo.BasePhotoInfo.PicPath);

                        }
                        RasterImage smallPicImage = CreatePicImgV(picInfo, codecs, board);//   横向排竖向生产旋转竖向取反
                        DrowPicLine(ref smallPicImage, Color.Green);
                        int angel = 0;        ///旋转角度
                        Status.PhotoBarCodeLocal barCodeLocal = COM.Status.PhotoBarCodeLocal.Bottom;    //条码所在方向
                        UPTLab("正在合成中间图");
                        RasterImage midImageTmp = CreateMidImgV(picInfo);//带有条码的中间图是竖版中间图
                        //UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)


                        //是否有备注
                        if (picInfo.barCodeStatus != SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode)//有条码
                        {

                            Color backColorBarcode = new Color();
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board, out backColorBarcode);//条码图片的临时图片
                            if (DateTransfer.PhotoRemarkFlag == 0)
                            {

                            }
                            else
                            {
                                double gray = backColorBarcode.R * 0.299 + 0.587 * backColorBarcode.G + 0.114 * backColorBarcode.B;
                                if (gray >= 128)
                                {
                                    FontColor = Color.Black;
                                }
                                else
                                {
                                    FontColor = Color.FromArgb(255, 255, 255);
                                }
                                //FontColor = Color.FromArgb(255-backColorBarcode.R,255-backColorBarcode.G,255-backColorBarcode.B);
                            }
                            //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            RasterImage ColorImgBlock = DateTransfer.PhotoRemarkFlag == 0 ? GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId) : GetColorBlockTextBackcolor(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                            UPTLab("粘贴色块");
                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                             0,
                             0,
                             barcodeImageTemp.Width,
                             barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);


                            UPTLab("生成条码及文字");

                            #region 打印条码及文字信息
                            Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            g.SmoothingMode = SmoothingMode.None;
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            int recX = ColorImgBlock.Width + 5, recY = -2;
                            string Barcode = "";
                            string nullBar = " ";
                            SizeF sizeF;
                            if (DateTransfer.SelectBarCodeType == 1)
                            {
                                recX += 20;
                                //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                            }
                            else if (DateTransfer.SelectBarCodeType == 0)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                //if (IsNum(tempBarcode))
                                //{
                                //    Barcode = "*" + tempBarcode + "*";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                //else
                                //{
                                //    Barcode = "";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                Barcode = "*" + tempBarcode + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                            }
                            else if (DateTransfer.SelectBarCodeType == 3)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('『');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('』');
                                if (startIndex == -1 || endIndex == -1)
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }
                                else
                                {
                                    string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                    //if (IsNum(tempBarcode))
                                    //{
                                    //    Barcode = "*" + tempBarcode + "*";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    //else
                                    //{
                                    //    Barcode = "";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    Barcode = "*" + tempBarcode + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                                }
                            }
                            else
                            {
                                Barcode = "";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                            }

                            BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度
                            //BARCODEWIDTH = Convert.ToInt16(sizeF.Width / gFont.DpiX * board.BoardBaseInfo.DPI)*2;



                            //色块就有50
                            //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                            {


                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                //g.DrawString (Brushes

                                //processor.Draw3dShape(g, SpecialEffectsShape.Rectangle, rc, Color.White, null, rc, SpecialEffectsBackStyle.Opaque, Color.White, SpecialEffectsFillStyle.Solid, Color.White, SpecialEffectsBorderStyle.Solid, 0, Color.White, Color.White, SpecialEffectsInnerStyle.None, 0, Color.White, Color.White, SpecialEffectsOuterStyle.None, 0, 0, 0, Color.White, null);

                                processor.Draw3dText(g,
                                                    Barcode,
                                                    rc,
                                                    SpecialEffectsTextStyle.Normal,
                                                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                    0, /* horizontal  shadow position */
                                                    0, /* vertical shadow position */
                                                    Color.Black,/* text color, blue */
                                                    Color.White,/* shadow color, black */
                                                    Color.White, /* border color, white */
                                                    textBarFont3o92,
                                                    null);





                                recX += BARCODEWIDTH;

                            }
                            else
                            {

                            }


                            //写其文字信息

                            recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            string productName = "";
                            string leftProduct = "";
                            picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                            int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                            if (PIndex > 0)
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex);
                            }
                            else
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName;
                                leftProduct = "-";
                            }


                            string text = "";
                            try
                            {
                                text = GetBarCodeStringByCutsom(picInfo, board).Trim('\\');
                            }
                            catch
                            {

                            }
                            SizeF sizetextF = gFont.MeasureString(text, textFont);

                            StringFormat textFormat = new StringFormat();
                            textFormat.Alignment = StringAlignment.Near;
                            textFormat.LineAlignment = StringAlignment.Center;
                            textFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;

                            //textFormat.
                            Rectangle rcFont = new Rectangle(recX - 20, 2, barcodeImageTemp.Width - recX, BARCODEHEIDHT);


                            gFont.PageUnit = GraphicsUnit.Pixel;

                            string newText = text;
                            if (DateTransfer.TextAlignType == 0)//左
                            {
                                newText = text;
                            }
                            else if (DateTransfer.TextAlignType == 1)//右对齐
                            {
                                for (int m = 0; m < text.Length; m++)
                                {
                                    newText = text.Substring(m);

                                    SizeF sizenewtextF = gFont.MeasureString(newText, textFont, barcodeImageTemp.Width - recX, textFormat);

                                    if (sizenewtextF.Width <= (barcodeImageTemp.Width - recX) * gFont.DpiX / board.BoardBaseInfo.DPI)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                newText = text;
                                textFormat.Alignment = StringAlignment.Center;
                                textFormat.LineAlignment = StringAlignment.Center;
                            }


                            g.PageUnit = GraphicsUnit.Pixel;
                            g.DrawString(newText, textFont, new SolidBrush(FontColor), rcFont, textFormat);


                            //codecs.Save(barcodeImageTemp, @"c:\\barcodeImageTemp.jpg", RasterImageFormat.Jpeg, 24);

                            g.Dispose();
                            //gFont.Dispose();
                            ColorImgBlock.Dispose();//释放色块的资源
                            #endregion

                            UPTLab("正在粘贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            Rectangle barCodeRec, picRec;
                            ///注释：中间图以及原图竖版合成的
                            ///原图是旋转270度放置 中间图无方向 但是竖向的
                            ///条码的方向是针对中间图的跟照片原方向木有关系
                            ///越多左右方向0右1左 上下方向下0上1
                            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom)
                            {
                                //竖版生成在竖方向相对于原方向的横方向
                                //条码备注在中间图的左右方向 
                                if (!picInfo.IsWhirl)
                                {
                                    //实际是在图的上下方向
                                    if (DateTransfer.RemarkInPicBottomOrTop == 0)
                                    {

                                        //旋转270度后右边边就是照片的下面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = SmallERP.COM.Status.PhotoBarCodeLocal.Right;
                                    }
                                    else//
                                    {
                                        //旋转270度后左边就是照片的上面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = SmallERP.COM.Status.PhotoBarCodeLocal.Left;
                                    }
                                }
                                else
                                {
                                    //照片的实际方向横竖方向是没有变的
                                    //实际是在图的上下方向
                                    if (DateTransfer.RemarkInPicRightOrLeft == 0)
                                    {
                                        //右边就是照片的右面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = SmallERP.COM.Status.PhotoBarCodeLocal.Right;
                                    }
                                    else//左边就是照片的左边
                                    {
                                        //旋转270度后右边就是照片的上面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = SmallERP.COM.Status.PhotoBarCodeLocal.Left;
                                    }
                                }


                            }
                            else  //0:条码在中间图的上下方向
                            {
                                if (!picInfo.IsWhirl)
                                {
                                    if (DateTransfer.RemarkInPicRightOrLeft == 0)
                                    {
                                        //右边就是打相对于照片的上面
                                        //barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, BARCODEHEIDHT);
                                        //picRec = new Rectangle(0, BARCODEHEIDHT, smallPicImage.Width, smallPicImage.Height);
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = SmallERP.COM.Status.PhotoBarCodeLocal.Top;
                                    }
                                    else
                                    {
                                        //左边就是打相对于照片下面

                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = SmallERP.COM.Status.PhotoBarCodeLocal.Bottom;
                                    }
                                }
                                else//旋转过
                                {
                                    if (DateTransfer.RemarkInPicBottomOrTop == 0)
                                    {



                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, smallPicImage.Height);
                                        barCodeLocal = SmallERP.COM.Status.PhotoBarCodeLocal.Bottom;
                                    }
                                    else
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, smallPicImage.Height);
                                        barCodeLocal = SmallERP.COM.Status.PhotoBarCodeLocal.Top;

                                    }
                                }
                            }

                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            cfcBarcode.SourcePoint = Point.Empty;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.DestinationImage = midImageTmp;



                            cfcBarcode.DestinationRectangle = barCodeRec;
                            cfcBarcode.Run(barcodeImageTemp);

                            //UPTLab("贴图片");
                            //贴图片
                            cfcBarcode.DestinationRectangle = picRec;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.Run(smallPicImage);

                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                            #endregion

                        }
                        else//无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                                                               0,
                                                                               0,
                                                                               smallPicImage.Width,
                                                                               smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }
                        #endregion

                        UPTLab("正在绘制中间图边框");
                        #region //给中间图画边框
                        if (DateTransfer.IsPrintLine)
                        {
                            Graphics g2 = null;
                            try
                            {

                                DrowBordLine(ref midImageTmp);

                            }
                            catch (Exception Boardex)//如果添加边框出错就不添加
                            {
                                WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.BasePhotoInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                                DrowBordLine(ref midImageTmp);

                            }
                            finally
                            {
                                if (g2 != null)
                                {
                                    g2.Dispose();
                                }
                            }
                        }
                        #endregion
                        UPTLab("正在粘贴图片:ID" + picInfo.BasePhotoInfo.PhotoId + ",照片" + picInfo.BasePhotoInfo.PicPath);
                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }
                        ///转换坐标
                        /// 
                        int picLocalX = pointY;
                        int picLocalY = pointX + offsetH;


                        //CombineFastCommand midCommand = new CombineFastCommand();
                        //midCommand.DestinationRectangle = new Rectangle(
                        //     pointY,//在大图上的坐标
                        //     pointX + offsetH,
                        //    midImageTmp.Width,//长和宽
                        //    midImageTmp.Height);
                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                             picLocalX,//在大图上的坐标
                            picLocalY,
                            midImageTmp.Width,//长和宽
                            midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (board.IsTransverse)//自动裁切模式IsTransverse 改为是否使用裁切选择项目
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();
                            //photoP.X = pointY;                                                                                    //photoP.Y = pointX;
                            photoP.X = picLocalX;
                            photoP.Y = picLocalY - offsetH;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;
                            photoP.BarCodeLocal = barCodeLocal;

                            if (picInfo.IsWhirl)
                            {
                                photoP.Angle = 0;
                            }
                            else
                            {
                                photoP.Angle = 270;
                            }
                            //计算DXF宽高
                            if (!string.IsNullOrEmpty(picInfo.BasePhotoInfo.DXFFilePath))
                            {
                                SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.BasePhotoInfo.DXFContent);
                                DxfObjecctInfo mindxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                                DxfObjecctInfo maxdxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                                DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                                DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                                photoP.DXFWidth = maxPointer.X - minPointer.X;
                                photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                                photoP.DXFContent = picInfo.BasePhotoInfo.DXFContent;
                                photoP.DxfPath = picInfo.BasePhotoInfo.DXFFilePath;
                            }
                            else
                            {
                                photoP.DXFWidth = 0;
                                photoP.DXFHeigth = 0;
                                photoP.DXFContent = null;
                            }

                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.PhotoS.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.BasePhotoInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.BasePhotoInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;

                cfctop.DestinationRectangle = new Rectangle(0, destHegth - offsetH, smallBottom.Width, smallBottom.Height);
                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                cfctop.Run(smallBottom);


                if (DateTransfer.CutMinPhotoNum == 0)
                {
                    //不处理
                }
                else
                {
                    if (board.PhotoS.Count <= DateTransfer.CutMinPhotoNum)
                    {
                        DateTransfer.IsAutoCut = false;
                    }
                    else
                    {
                        //不处理
                    }
                }

                //写入文件 
                StringBuilder sbWriter = new StringBuilder();
                //sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.DPI);
                sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.PrinterName.Trim());
                foreach (PhotoPoint pp in listPhotoInfoForCut)
                {

                    //int picImageWidth = midImageTmp.Width;
                    //int picImageHeigth = midImageTmp.Height;
                    //if (_cutNoBarcode)
                    //{
                    //    if (barCodeLocal == SmallERP.COM.Status.PhotoBarCodeLocal.Left)
                    //    {
                    //        picLocalX = picLocalX + BARCODEHEIDHT;
                    //        picImageWidth = picImageWidth - BARCODEHEIDHT;
                    //    }  else if (barCodeLocal == SmallERP.COM.Status.PhotoBarCodeLocal.Right)
                    //    {
                    //        //picLocalX = picLocalX + BARCODEHEIDHT;
                    //        picImageWidth = picImageWidth - BARCODEHEIDHT;
                    //    }    else if (barCodeLocal == SmallERP.COM.Status.PhotoBarCodeLocal.Top)
                    //    {
                    //        picLocalY += BARCODEHEIDHT;
                    //        picImageHeigth -= BARCODEHEIDHT;
                    //    }      else if (barCodeLocal == SmallERP.COM.Status.PhotoBarCodeLocal.Bottom)
                    //    {
                    //        picImageHeigth -= BARCODEHEIDHT;
                    //    }
                    //}
                    int xVar = 0;
                    int yVar = 0;
                    int wVar = 0;

                    int hVar = 0;
                    int variable = Convert.ToInt32((double)BARCODEHEIDHT / board.BoardBaseInfo.DPI * 2.54 * 100);
                    if (_cutNoBarcode)
                    {
                        if (pp.BarCodeLocal == SmallERP.COM.Status.PhotoBarCodeLocal.Left)
                        {
                            xVar = variable; 
                            wVar = -variable;
                        }
                        else if (pp.BarCodeLocal == SmallERP.COM.Status.PhotoBarCodeLocal.Right)
                        {
                            wVar = -variable;
                        }
                        else if (pp.BarCodeLocal == SmallERP.COM.Status.PhotoBarCodeLocal.Top)
                        {
                            yVar = variable;
                            hVar = -variable;
                        }
                        else if (pp.BarCodeLocal == SmallERP.COM.Status.PhotoBarCodeLocal.Bottom)
                        {
                            hVar = -variable;
                        }

                    }

                    int merginMMcCen = 0;
                    int merginMMWH = 0;
                    int merginMidWidth = 0;
                    int merginMidHeight = 0;
                    int merginRx = 0;
                    int merginRy = 0;
                    double chanePara = 1d / board.BoardBaseInfo.DPI * 2.54 * 100;
                    if (curBleed.Type == 0)
                    {
                        merginRx = merginRy = Convert.ToInt32(curBleed.Value * 10);
                        //MerginMMWH = Convert.ToInt32((curBleed.Value*10*2);
                        merginMidWidth = merginMidHeight = Convert.ToInt32(curBleed.Value * 10 * 2); ;
                    }
                    else
                    {

                        if (pp.Width >= pp.Height)
                        {
                            //double h = pp.Height;
                            merginMidHeight = Convert.ToInt32(pp.Height * curBleed.Value / 100 * chanePara);
                            merginMidWidth = Convert.ToInt32(pp.Width * merginMidHeight / (pp.Height * chanePara));
                            //merginRx = merginMidWidth / 2;
                            //merginRy = merginMidHeight / 2;
                        }
                        else
                        {
                            merginMidWidth = Convert.ToInt32(pp.Width * curBleed.Value / 100 * chanePara);
                            merginMidHeight = Convert.ToInt32(pp.Height * merginMidWidth / (pp.Width * chanePara));
                        }
                        merginRx = merginMidWidth / 2;
                        merginRy = merginMidHeight / 2;
                    }
                    ;
                    if (pp.DXFContent != null)
                    {
                        merginRx = merginRy = merginMidWidth = merginMidHeight = 0;
                    }


                    string mmX = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + merginRx + xVar)).ToString("0");
                    string mmy = (((double)pp.Y / board.BoardBaseInfo.DPI * 2.54 * 100 + merginRy + yVar)).ToString("0");
                    string mmWidth = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - merginMidWidth + wVar)).ToString("0");
                    string mmheight = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - merginMidHeight + hVar)).ToString("0");

                    string dxfFlag = "DXF";
                    string strWriter = "";
                    if (pp.DXFContent == null)
                    {
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                    }
                    else
                    {
                        string angleStr = pp.Angle.ToString();
                        string wScolar = "1";
                        string hScolar = "1";
                        int angleNum = pp.Angle / 90;
                        //if (angleNum % 2 == 0)
                        //{
                        //    wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                        //    hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                        //}
                        //else
                        //{
                        //    wScolar = (Convert.ToDouble(mmheight) / pp.DXFWidth / 10).ToString();
                        //    hScolar = (Convert.ToDouble(mmWidth) / pp.DXFHeigth / 10).ToString();
                        //}                                                                                                                                                                                                                                        
                        string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", "||");
                        //string dxfContent = NetDxfExtend.GetCutInfo(pp.DxfPath);                            
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                    hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                    }
                    sbWriter.AppendLine(strWriter);

                }
                string FileName = _curCutFileFullPath;
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                WrtieTextEn(sbWriter, FileName);
                EncryptionAndSave(board.BoardBaseInfo.BoardId, sbWriter);
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;

                if (board.AddSharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    SharpenCommand command = new SharpenCommand();
                    command.Sharpness = board.AddSharpen;
                    command.Run(destImage);
                }

                UPTLab("正在保存大图...");
                bool isNeedAddIcc = false;
                if (!string.IsNullOrEmpty(board.IccPath))
                {
                    if (board.IccPath.EndsWith(".icc") || board.IccPath.EndsWith(".icm"))
                    {
                        if (File.Exists(board.IccPath))
                        {
                            isNeedAddIcc = true;//只有当ICCPATH不为空字符串，则是以。ICC、ICM结尾的，且文件存在的才加ICC
                        }
                    }

                }
                if (DateTransfer.AddIccByType == 0)
                {
                    isNeedAddIcc = false;
                }
                if (isNeedAddIcc)//需要加载ICC
                {
                    if (DateTransfer.AddIccByType == 1)//需要用PS加载ICC
                    {
                        //先保存到本地,等加载好ICC时存到网络路径                  
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }

                        //再调用PS加载ICC
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                            }
                            catch { }
                            string strPicFormat = "JPEG";
                            //string strInputIcc = "ColorMatch RGB";
                            string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            if (board.IsTransverse)//竖向的就转90
                                intRatate = -90;
                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);
                                                        
                            string strResult = psApp.AddICC(iccName, strTempPath, destFileName);

                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件错误" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                            }
                            catch { }
                        }
                    }
                    else if (DateTransfer.AddIccByType == 2)
                    {
                        //调用IccProcessEXE 加载ICC

                        string tamPath = Environment.GetEnvironmentVariable("TEMP");
                        strTempPath = tamPath + "\\abc.jpg";
                        string iccPath = tamPath + board.IccPath.Substring(board.IccPath.LastIndexOf("\\"));
                        string loadediccPath = tamPath + "\\def.jpg";
                        string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        string fromTempICC = tamPath + "\\sRGB Color Space Profile.icm";
                        string exePath = Application.StartupPath + "\\IccProcessEXE.exe";
                        if (File.Exists(strTempPath))
                        {
                            File.Delete(strTempPath);
                        }
                        if (File.Exists(loadediccPath))
                        {
                            File.Delete(loadediccPath);
                        }
                        if (!File.Exists(iccPath))
                        {
                            File.Copy(board.IccPath, iccPath);
                        }
                        if (!File.Exists(fromTempICC))
                        {
                            File.Copy(FromIcc, fromTempICC);
                        }
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }
                        string iccFile = "";

                        //string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        try
                        {
                            UPTLab("正在加载ICC:" + board.IccPath);

                            using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                            {
                                pExecuteEXE.StartInfo.FileName = exePath;
                                //pExecuteEXE.StartInfo.Arguments = @"c:\1410.jpg,c:\sRGB Color Space Profile.icm,c:\efg1.jpg,c:\dnp100305-003.icm,95";
                                //pExecuteEXE.StartInfo.Arguments = doubleQM + strTempPath + doubleQM + "," + doubleQM + fromTempICC + doubleQM + "," + doubleQM + loadediccPath + doubleQM + "," + doubleQM+iccPath+doubleQM + "," + 95;
                                pExecuteEXE.StartInfo.Arguments = strTempPath + "," + doubleQM + fromTempICC + doubleQM + "," + loadediccPath + "," + doubleQM + iccPath + doubleQM + "," + 95;

                                pExecuteEXE.Start();
                                pExecuteEXE.WaitForExit();
                            }

                            //iccFile = iccLoad.IccProcess(strTempPath, fromTempICC, loadediccPath, iccPath,"100");
                            //if (!loadediccPath.Equals(iccFile))
                            //{
                            //    UPTLab("加载ICC文件错误:");
                            //    throw new Exception("加载ICC文件错误");

                            //}
                            //else
                            //{
                            //    File.Copy(loadediccPath, destFileName);
                            //}
                            if (File.Exists(loadediccPath))
                            {
                                try
                                {
                                    File.Copy(loadediccPath, destFileName, true);
                                }
                                catch (Exception ex)
                                {
                                    UPTLab("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有路径访问权限");
                                    throw new Exception("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有改路径访问权限");

                                }
                            }
                        }
                        catch
                        {
                        }

                    }
                    else if (DateTransfer.AddIccByType == 3)
                    {
                        //LEADTOOLS加载ICC


                        try
                        {

                            //IccProfileExtended iccProfile = new IccProfileExtended();

                            //// load the ICC from an image, by specifying the image's name, and the 1-based page number that contains the ICC. 
                            //// to load the ICC from an Image that is in a stream, put the stream instead of the file name. 
                            //iccProfile.ReadFromImage(@"E:\开单目录\back-wall-ms  山富灯片ok曲线\25.5x17.4x25.tif", 1);

                            //// at this point, the iccProfile object contains the ICC profile that was found in the image, 
                            //// you can use it as you want, but for this example, we will save it in a seperate ICC profile file. 
                            //// generate the profileId. For the time being, it will be filled with 0's 
                            //iccProfile.GenerateProfileId();

                            //// finally generate the new Icc Profile by updating the Data Array 
                            //// and then generating the file 
                            //iccProfile.UpdateDataArray();
                            switch (PicFormat)
                            {
                                case 0: codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Jpeg, 24);
                                    break;
                                case 1:
                                    codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Tif, 24);
                                    break;
                            }
                            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                            //IccProfileExtended iccP=new IccProfileExtended((
                            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                        }
                        catch (Exception ef)
                        {

                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }




                    }
                    else
                    {



                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                                break;
                        }


                    }
                }
                else//不需要加载ICC，则直接保存
                {


                    switch (PicFormat)
                    {
                        case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }
                }

                #region //写入ICC文件

                //UPTLab("正在加载ICC文件..." + board.IccPath);
                //if (!string.IsNullOrEmpty(board.IccPath))
                //{
                //    if (DateTransfer.AddIccByPs)//需要用PS加载ICC
                //    {
                //        try
                //        {
                //            //iCC的名称，需要与PS中的一致
                //            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                //            iccName = iccName.Substring(0, iccName.IndexOf("."));
                //            try
                //            {
                //                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                //            }
                //            catch { }
                //            string strPicFormat = "JPEG";
                //            string strInputIcc = "ColorMatch RGB";
                //            int intRatate = 0;
                //            if (board.IsTransverse)//竖向的就转90
                //                intRatate = -90;
                //            PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                //            //MessageBox.Show("请查看"+strTempPath+"是否有图片");
                //            string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);

                //            if (strResult == destFileName)
                //            {
                //                //MessageBox.Show("保存到" + destFileName);
                //                UPTLab("成功加载ICC文件!");
                //            }
                //            else
                //            {
                //                //MessageBox.Show("加载失败了！");
                //                //加载ICC失败
                //                UPTLab("加载ICC文件失败!" + strResult);
                //            }
                //        }
                //        catch (Exception ex)
                //        {
                //            throw new Exception("加载ICC文件错误" + ex.Message);
                //        }
                //        finally
                //        {
                //            try
                //            {
                //                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                //            }
                //            catch { }
                //        }
                //    }
                //    else   //用LEADTOOLS加载ICC
                //    {
                //        try
                //        {
                //            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                //            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                //        }
                //        catch (Exception ef)
                //        {
                //            UPTLab("加载ICC文件错误:" + ef.Message);
                //            throw new Exception("加载ICC文件错误" + ef.Message);
                //        }
                //    }
                //}
                #endregion


                destImage.Dispose();


                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                board.BoardBaseInfo.PicPath = destFileName;
                _mainBLL.MakeBigPicSusscess(board);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString());


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //_mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                int boardstatus = _mainBLL.SetBoardStatus2(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                if (boardstatus == 0)
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":无法修改Board状态，如有必要手动删除版" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                else
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                UPTLabBoardErrorList();
            }
            finally
            {
                errText = "";
            }
        }
        /// <summary>
        /// 横向拼版竖向生成裁切标记在下方
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2VCutAfterPic(BoardInfo_MakeBigPic board)
        {
            int XExcursion = 0;//X坐标偏移量
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            //int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            //int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            int boardPixWidth = board.BoardBaseInfo.Height; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.Length;//大图的高,相素高宽互换

            //XExcursion = boardPixWidth;
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸
            if (DateTransfer.SaveFileType == 1)
            {
                PicFormat = 1;
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            else
            {
                PicFormat = 0;
            }

            DateTransfer.IsAutoCut = board.IsTransverse;

            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {
                //创建裁切标
                RasterCodecs codecs = new RasterCodecs();
                string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                int offsetH = smallTop.Height;
                int destHeight = BoardPixHeight + offsetH;
                int photoYOffset = 0;
                RasterImage smallBottom = null;
                if (DateTransfer.TwoCutFlag)
                {
                    aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", "", "");
                    smallBottom = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                    destHeight += offsetH;
                    photoYOffset = offsetH;
                }
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    boardPixWidth,//+1保证最右边的框线可以出来
                    //BoardPixHeight + offsetH,
                    destHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                Color backColor = DateTransfer.BackColor;

                FillCommand fcommand = new FillCommand();
                //fcommand.Color = new RasterColor(128, 128, 128);
                fcommand.Color = new RasterColor(backColor);

                fcommand.Run(destImage);

                //旋转裁切标记
                RotateCommand rcSmall = new RotateCommand();//旋转条码图片               
                rcSmall.Angle = 180 * 100;
                rcSmall.FillColor = new RasterColor(255, 255, 255);
                rcSmall.Flags = RotateCommandFlags.Resize;
                rcSmall.Run(smallTop);
                //rcSmall.Run(smallBottom);

                //粘贴裁切标记
                CombineFastCommand cfctop = new CombineFastCommand();

                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;

                cfctop.DestinationRectangle = new Rectangle(0, destHeight - offsetH, smallTop.Width, smallTop.Height);

                cfctop.Run(smallTop);
                if (DateTransfer.TwoCutFlag)
                {
                    cfctop.DestinationRectangle = new Rectangle(0, 0, smallBottom.Width, smallBottom.Height);
                    cfctop.Run(smallBottom);
                }
                codecs.Save(destImage, "d:\\1.jpg", RasterImageFormat.Jpeg, 24);
                UPTLab("渲染大图框架成功");
                foreach (var picInfo in board.PhotoS)
                {
                    UPTLab("正在添加小图:" + picInfo.BasePhotoInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上
                        // 根据加急级别以及是否清空等确定字体的颜色
                        if (!File.Exists(picInfo.BasePhotoInfo.PicPath))
                        {
                            throw new Exception("文件未找到:" + picInfo.BasePhotoInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        if (!string.IsNullOrEmpty(DateTransfer.RemarkKeysColor))
                        {
                            FontColor = GetRemarkColor(picInfo.BasePhotoInfo.PicPath);

                        }
                        RasterImage smallPicImage = CreatePicImgV(picInfo, codecs, board);//
                        DrowPicLine(ref smallPicImage, Color.Green);
                        UPTLab("正在合成中间图");
                        RasterImage midImageTmp = CreateMidImgV(picInfo);//带有条码的中间图是竖版中间图
                        //UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)


                        //是否有备注
                        if (picInfo.barCodeStatus != SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode)//有条码
                        {

                            Color backColorBarcode = new Color();
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board, out backColorBarcode);//条码图片的临时图片
                            if (DateTransfer.PhotoRemarkFlag == 0)
                            {

                            }
                            else
                            {
                                double gray = backColorBarcode.R * 0.299 + 0.587 * backColorBarcode.G + 0.114 * backColorBarcode.B;
                                if (gray >= 128)
                                {
                                    FontColor = Color.Black;
                                }
                                else
                                {
                                    FontColor = Color.FromArgb(255, 255, 255);
                                }
                                //FontColor = Color.FromArgb(255-backColorBarcode.R,255-backColorBarcode.G,255-backColorBarcode.B);
                            }
                            //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            RasterImage ColorImgBlock = DateTransfer.PhotoRemarkFlag == 0 ? GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId) : GetColorBlockTextBackcolor(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                            UPTLab("粘贴色块");
                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                             0,
                             0,
                             barcodeImageTemp.Width,
                             barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);


                            UPTLab("生成条码及文字");

                            #region 打印条码及文字信息
                            Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            g.SmoothingMode = SmoothingMode.None;
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            int recX = ColorImgBlock.Width + 5, recY = -2;
                            string Barcode = "";
                            string nullBar = " ";
                            SizeF sizeF;
                            if (DateTransfer.SelectBarCodeType == 1)
                            {
                                recX += 20;
                                //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                            }
                            else if (DateTransfer.SelectBarCodeType == 0)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                //if (IsNum(tempBarcode))
                                //{
                                //    Barcode = "*" + tempBarcode + "*";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                //else
                                //{
                                //    Barcode = "";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                Barcode = "*" + tempBarcode + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                            }
                            else if (DateTransfer.SelectBarCodeType == 3)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('『');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('』');
                                if (startIndex == -1 || endIndex == -1)
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }
                                else
                                {
                                    string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                    //if (IsNum(tempBarcode))
                                    //{
                                    //    Barcode = "*" + tempBarcode + "*";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    //else
                                    //{
                                    //    Barcode = "";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    Barcode = "*" + tempBarcode + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                                }
                            }
                            else
                            {
                                Barcode = "";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                            }

                            BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度
                            //BARCODEWIDTH = Convert.ToInt16(sizeF.Width / gFont.DpiX * board.BoardBaseInfo.DPI);
                            //BARCODEWIDTH = BARCODEWIDTH * 2;


                            //色块就有50
                            //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                            {
                                //打条码
                                //Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                ////g.DrawString (Brushes

                                //processor.Draw3dShape(g, SpecialEffectsShape.Rectangle, rc, Color.White, null, rc, SpecialEffectsBackStyle.Opaque, Color.White, SpecialEffectsFillStyle.Solid, Color.White, SpecialEffectsBorderStyle.Solid, 0, Color.White, Color.White, SpecialEffectsInnerStyle.None, 0, Color.White, Color.White, SpecialEffectsOuterStyle.None, 0, 0, 0, Color.White, null);


                                //StringFormat barFormat = new StringFormat();
                                //barFormat.Alignment = StringAlignment.Center;
                                //barFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;
                                //barFormat.LineAlignment = StringAlignment.Center;
                                ////Rectangle rcBarcode = new Rectangle(rc.X, rc.Y, Convert.ToInt16(rc.Width / gFont.DpiX * board.BoardBaseInfo.DPI), Convert.ToInt16(rc.Height / gFont.DpiX * board.BoardBaseInfo.DPI));

                                //Font barF = DateTransfer.SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o92;
                                //g.DrawString(Barcode, barF, new SolidBrush(Color.Black), rc, barFormat);
                                //g.DrawString("123", textFont, new SolidBrush(Color.Black), rc,barFormat);


                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                //g.DrawString (Brushes

                                //processor.Draw3dShape(g, SpecialEffectsShape.Rectangle, rc, Color.White, null, rc, SpecialEffectsBackStyle.Opaque, Color.White, SpecialEffectsFillStyle.Solid, Color.White, SpecialEffectsBorderStyle.Solid, 0, Color.White, Color.White, SpecialEffectsInnerStyle.None, 0, Color.White, Color.White, SpecialEffectsOuterStyle.None, 0, 0, 0, Color.White, null);

                                processor.Draw3dText(g,
                                                    Barcode,
                                                    rc,
                                                    SpecialEffectsTextStyle.Normal,
                                                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                    0, /* horizontal  shadow position */
                                                    0, /* vertical shadow position */
                                                    Color.Black,/* text color, blue */
                                                    Color.White,/* shadow color, black */
                                                    Color.White, /* border color, white */
                                                    textBarFont3o92,
                                                    null);



                                //StringFormat barFormat = new StringFormat();
                                //barFormat.Alignment = StringAlignment.Center;
                                //barFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;
                                //barFormat.LineAlignment = StringAlignment.Center;
                                ////Rectangle rcBarcode = new Rectangle(rc.X, rc.Y, Convert.ToInt16(rc.Width / gFont.DpiX * board.BoardBaseInfo.DPI), Convert.ToInt16(rc.Height / gFont.DpiX * board.BoardBaseInfo.DPI));

                                //Font barF = DateTransfer.SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o92;
                                //g.DrawString(Barcode, barF, new SolidBrush(Color.Black), rc, barFormat);
                                //g.DrawString("123", textFont, new SolidBrush(Color.Black), rc,barFormat);

                                recX += BARCODEWIDTH;

                            }
                            else
                            {

                            }


                            //写其文字信息

                            recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            string productName = "";
                            string leftProduct = "";
                            picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                            int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                            if (PIndex > 0)
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex);
                            }
                            else
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName;
                                leftProduct = "-";
                            }


                            string text = "";
                            try
                            {
                                text = GetBarCodeStringByCutsom(picInfo, board).Trim('\\');
                            }
                            catch
                            {

                            }
                            SizeF sizetextF = gFont.MeasureString(text, textFont);

                            StringFormat textFormat = new StringFormat();
                            textFormat.Alignment = StringAlignment.Near;
                            textFormat.LineAlignment = StringAlignment.Center;
                            textFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;

                            //textFormat.
                            Rectangle rcFont = new Rectangle(recX - 20, 2, barcodeImageTemp.Width - recX, BARCODEHEIDHT);


                            gFont.PageUnit = GraphicsUnit.Pixel;

                            string newText = text;
                            if (DateTransfer.TextAlignType == 0)//左
                            {
                                newText = text;
                            }
                            else if (DateTransfer.TextAlignType == 1)//右对齐
                            {
                                for (int m = 0; m < text.Length; m++)
                                {
                                    newText = text.Substring(m);

                                    SizeF sizenewtextF = gFont.MeasureString(newText, textFont, barcodeImageTemp.Width - recX, textFormat);

                                    if (sizenewtextF.Width <= (barcodeImageTemp.Width - recX) * gFont.DpiX / board.BoardBaseInfo.DPI)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                newText = text;
                                textFormat.Alignment = StringAlignment.Center;
                                textFormat.LineAlignment = StringAlignment.Center;
                            }


                            g.PageUnit = GraphicsUnit.Pixel;
                            g.DrawString(newText, textFont, new SolidBrush(FontColor), rcFont, textFormat);


                            //codecs.Save(barcodeImageTemp, @"c:\\barcodeImageTemp.jpg", RasterImageFormat.Jpeg, 24);

                            g.Dispose();
                            //gFont.Dispose();
                            ColorImgBlock.Dispose();//释放色块的资源
                            #endregion

                            UPTLab("正在粘贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            Rectangle barCodeRec, picRec;
                            ///注释：中间图以及原图竖版合成的
                            ///原图是旋转270度放置 中间图无方向 但是竖向的
                            ///条码的方向是针对中间图的跟照片原方向木有关系
                            ///越多左右方向0右1左 上下方向下0上1
                            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.TopOrBottom)
                            {
                                //竖版生成在竖方向相对于原方向的横方向
                                //条码备注在中间图的左右方向 
                                if (!picInfo.IsWhirl)
                                {
                                    //实际是在图的上下方向
                                    if (DateTransfer.RemarkInPicBottomOrTop == 0)
                                    {

                                        //旋转270度后右边边就是照片的下面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                    else//
                                    {
                                        //旋转270度后左边就是照片的上面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                }
                                else
                                {
                                    //照片的实际方向横竖方向是没有变的
                                    //实际是在图的上下方向
                                    if (DateTransfer.RemarkInPicRightOrLeft == 0)
                                    {
                                        //右边就是照片的右面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                    else//左边就是照片的左边
                                    {
                                        //旋转270度后右边就是照片的上面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                }


                            }
                            else  //0:条码在中间图的上下方向
                            {
                                if (!picInfo.IsWhirl)
                                {
                                    if (DateTransfer.RemarkInPicRightOrLeft == 0)
                                    {
                                        //右边就是打相对于照片的上面
                                        //barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, BARCODEHEIDHT);
                                        //picRec = new Rectangle(0, BARCODEHEIDHT, smallPicImage.Width, smallPicImage.Height);
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                    else
                                    {
                                        //左边就是打相对于照片下面

                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                }
                                else//旋转过
                                {
                                    if (DateTransfer.RemarkInPicBottomOrTop == 0)
                                    {



                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, smallPicImage.Height);
                                    }
                                    else
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, smallPicImage.Height);
                                    }
                                }
                            }

                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            cfcBarcode.SourcePoint = Point.Empty;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.DestinationImage = midImageTmp;



                            cfcBarcode.DestinationRectangle = barCodeRec;
                            cfcBarcode.Run(barcodeImageTemp);

                            //UPTLab("贴图片");
                            //贴图片
                            cfcBarcode.DestinationRectangle = picRec;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.Run(smallPicImage);

                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                            #endregion

                        }
                        else//无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                                                               0,
                                                                               0,
                                                                               smallPicImage.Width,
                                                                               smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }
                        #endregion

                        UPTLab("正在绘制中间图边框");
                        #region //给中间图画边框
                        if (DateTransfer.IsPrintLine)
                        {
                            Graphics g2 = null;
                            try
                            {

                                DrowBordLine(ref midImageTmp);

                            }
                            catch (Exception Boardex)//如果添加边框出错就不添加
                            {
                                WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.BasePhotoInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                                DrowBordLine(ref midImageTmp);

                            }
                            finally
                            {
                                if (g2 != null)
                                {
                                    g2.Dispose();
                                }
                            }
                        }
                        #endregion
                        UPTLab("正在粘贴图片:ID" + picInfo.BasePhotoInfo.PhotoId + ",照片" + picInfo.BasePhotoInfo.PicPath);
                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }



                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                                                                        pointY,//在大图上的坐标
                                                                        pointX + photoYOffset,  //如果有第二条的话 有偏移量
                                                                        midImageTmp.Width,//长和宽
                                                                        midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (board.IsTransverse)//自动裁切模式IsTransverse 改为是否使用裁切选择项目
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();



                            ///先计算右下角坐标
                            //photoP.X = pointY;
                            //photoP.Y = pointX;
                            photoP.X = board.BoardBaseInfo.Height - (pointY + midImageTmp.Width);
                            photoP.Y = board.BoardBaseInfo.Length - (pointX + midImageTmp.Height);
                            if (photoP.Y < 0)
                            {
                                photoP.Y = 0;
                            }
                            if (photoP.X < 0)
                            {
                                photoP.X = 0;
                            }
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;

                            if (!picInfo.IsWhirl)
                            {
                                photoP.Angle = 180;
                            }
                            else
                            {
                                photoP.Angle = 270;
                            }
                            //计算DXF宽高
                            if (!string.IsNullOrEmpty(picInfo.BasePhotoInfo.DXFFilePath))
                            {
                                //DxfExtend.GetFileContent(picInfo.BasePhotoInfo.DXFFilePath);
                                SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.BasePhotoInfo.DXFContent);
                                DxfObjecctInfo mindxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                                DxfObjecctInfo maxdxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                                DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                                DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                                photoP.DXFWidth = maxPointer.X - minPointer.X;
                                photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                                photoP.DXFContent = picInfo.DxfContent;
                            }
                            else
                            {
                                photoP.DXFWidth = 0;
                                photoP.DXFHeigth = 0;
                                photoP.DXFContent = null;
                            }




                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.PhotoS.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.BasePhotoInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.BasePhotoInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;

                int qipanHeight = Convert.ToInt32(0.5 / 2.54 * board.BoardBaseInfo.DPI);

                if (DateTransfer.CutMinPhotoNum == 0)
                {
                    //不处理
                }
                else
                {
                    if (board.PhotoS.Count <= DateTransfer.CutMinPhotoNum)
                    {
                        DateTransfer.IsAutoCut = false;
                    }
                    else
                    {
                        //不处理
                    }
                }
                //if (DateTransfer.IsAutoCut)//自动裁切模式要替换最终destImage
                //{
                //    UPTLab("创建自动裁切信息");
                //    ///创建大板的条码信息
                //    //RasterImage destTempImage = destImage;//先将名称替换掉

                //    //string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                //    //RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");

                //    //RasterImage boardPointInfoImage = new RasterImage(
                //    //                                    RasterMemoryFlags.Conventional,
                //    //                                    destImage.Height,
                //    //                                    qipanHeight,
                //    //                                    24,
                //    //                                    RasterByteOrder.Bgr,
                //    //                                    RasterViewPerspective.BottomLeft,
                //    //                                    null,
                //    //                                    IntPtr.Zero,
                //    //                                    0);//条码信息色块中间白板图

                //    //RasterImage destTempImage = new RasterImage(RasterMemoryFlags.Conventional,
                //    //                                    destImage.Width,
                //    //                                    destImage.Height + qipanHeight,
                //    //                                    24,
                //    //                                    RasterByteOrder.Bgr,
                //    //                                    RasterViewPerspective.BottomLeft,
                //    //                                    null,
                //    //                                    IntPtr.Zero,
                //    //                                    0);//);
                //    ///////填充颜色
                //    //FillCommand fcommandW = new FillCommand();
                //    //fcommandW.Color = new RasterColor(255, 255, 255);
                //    //fcommandW.Run(destTempImage);
                //    //fcommandW.Run(boardPointInfoImage);
                //    //destTempImage.XResolution = destImage.XResolution;

                //    //destTempImage.YResolution = destImage.YResolution;
                //    //条码文字信息
                //    //Graphics g = barcodeImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                //    //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                //    int recCurrX = XExcursion, recCurrY = 0;




                //    //#region
                //    ////打定位色块第一组
                //    //#region///棋盘定位
                //    RasterImage ColorImgBlockWhite = CreateColorBlock(Color.Black.R, Color.Black.G, Color.Black.B);
                //    RasterImage ColorImgBlockBlack = CreateColorBlock(Color.Black.R, Color.Black.G, Color.Black.B);



                //    UPTLab("粘贴色块");
                //    //ClassVectorPointClass cvpc = new ClassVectorPointClass();
                //    if (File.Exists(Application.StartupPath + "\\temBar.bmp"))
                //    {
                //        File.Delete(Application.StartupPath + "\\temBar.bmp");
                //    }

                //    //var p1 = mai.CreateMarkPictureToFile(Convert.ToInt32(boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                //    //Image img = Microsoft.VisualBasic.Compatibility.VB6.Support.IPictureToImage(p1);
                //    //RasterImage smallTop = new RasterImage(img);

                //    //CombineFastCommand cfctop = new CombineFastCommand();
                //    //cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                //    //cfctop.SourcePoint = Point.Empty;
                //    //cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                //    //cfctop.DestinationImage = destTempImage;
                //    //cfctop.Run(smallTop);
                //    //cfctop.DestinationRectangle = new Rectangle(0, qipanHeight, destImage.Width, destImage.Height);
                //    //cfctop.DestinationImage = destTempImage;
                //    //cfctop.Run(destImage);
                //    //destImage = destTempImage;//重新赋值


                //}
                //写入文件 
                StringBuilder sbWriter = new StringBuilder();
                //sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.DPI);
                sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.PrinterName.Trim());
                foreach (PhotoPoint pp in listPhotoInfoForCut)
                {
                    string mmX = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                    string mmy = (((double)pp.Y / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                    string mmWidth = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                    string mmheight = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                    string dxfFlag = "DXF";
                    string strWriter = "";
                    if (pp.DXFContent == null)
                    {
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                    }
                    else
                    {
                        string angleStr = pp.Angle.ToString();
                        string wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                        string hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                        string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", ";");
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                    hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                    }
                    sbWriter.AppendLine(strWriter);

                }
                string FileName = _curCutFileFullPath;
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                WrtieTextEn(sbWriter, FileName);
                EncryptionAndSave(board.BoardBaseInfo.BoardId, sbWriter);
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;

                if (board.AddSharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    SharpenCommand command = new SharpenCommand();
                    command.Sharpness = board.AddSharpen;
                    command.Run(destImage);
                }

                UPTLab("正在保存大图...");
                bool isNeedAddIcc = false;
                if (!string.IsNullOrEmpty(board.IccPath))
                {
                    if (board.IccPath.EndsWith(".icc") || board.IccPath.EndsWith(".icm"))
                    {
                        if (File.Exists(board.IccPath))
                        {
                            isNeedAddIcc = true;//只有当ICCPATH不为空字符串，则是以。ICC、ICM结尾的，且文件存在的才加ICC
                        }
                    }

                }
                if (DateTransfer.AddIccByType == 0)
                {
                    isNeedAddIcc = false;
                }
                if (isNeedAddIcc)//需要加载ICC
                {
                    if (DateTransfer.AddIccByType == 1)//需要用PS加载ICC
                    {
                        //先保存到本地,等加载好ICC时存到网络路径                  
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }

                        //再调用PS加载ICC
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                            }
                            catch { }
                            string strPicFormat = "JPEG";
                            //string strInputIcc = "ColorMatch RGB";
                            string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            if (board.IsTransverse)//竖向的就转90
                                intRatate = -90;
                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);


                            string strResult = psApp.AddICC(iccName, strTempPath, destFileName);


                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件错误" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                            }
                            catch { }
                        }
                    }
                    else if (DateTransfer.AddIccByType == 2)
                    {
                        //调用IccProcessEXE 加载ICC

                        string tamPath = Environment.GetEnvironmentVariable("TEMP");
                        strTempPath = tamPath + "\\abc.jpg";
                        string iccPath = tamPath + board.IccPath.Substring(board.IccPath.LastIndexOf("\\"));
                        string loadediccPath = tamPath + "\\def.jpg";
                        string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        string fromTempICC = tamPath + "\\sRGB Color Space Profile.icm";
                        string exePath = Application.StartupPath + "\\IccProcessEXE.exe";
                        if (File.Exists(strTempPath))
                        {
                            File.Delete(strTempPath);
                        }
                        if (File.Exists(loadediccPath))
                        {
                            File.Delete(loadediccPath);
                        }
                        if (!File.Exists(iccPath))
                        {
                            File.Copy(board.IccPath, iccPath);
                        }
                        if (!File.Exists(fromTempICC))
                        {
                            File.Copy(FromIcc, fromTempICC);
                        }
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }
                        string iccFile = "";
                        //string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        try
                        {
                            UPTLab("正在加载ICC:" + board.IccPath);

                            using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                            {
                                pExecuteEXE.StartInfo.FileName = exePath;
                                //pExecuteEXE.StartInfo.Arguments = @"c:\1410.jpg,c:\sRGB Color Space Profile.icm,c:\efg1.jpg,c:\dnp100305-003.icm,95";
                                //pExecuteEXE.StartInfo.Arguments = strTempPath + "," + fromTempICC + "," + loadediccPath + "," + iccPath + "," + 95;
                                pExecuteEXE.StartInfo.Arguments = strTempPath + "," + doubleQM + fromTempICC + doubleQM + "," + loadediccPath + "," + doubleQM + iccPath + doubleQM + "," + 95;
                                pExecuteEXE.Start();
                                pExecuteEXE.WaitForExit();
                            }

                            //iccFile = iccLoad.IccProcess(strTempPath, fromTempICC, loadediccPath, iccPath,"100");
                            //if (!loadediccPath.Equals(iccFile))
                            //{
                            //    UPTLab("加载ICC文件错误:");
                            //    throw new Exception("加载ICC文件错误");

                            //}
                            //else
                            //{
                            //    File.Copy(loadediccPath, destFileName);
                            //}
                            if (File.Exists(loadediccPath))
                            {
                                try
                                {
                                    File.Copy(loadediccPath, destFileName, true);
                                }
                                catch (Exception ex)
                                {
                                    UPTLab("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有路径访问权限");
                                    throw new Exception("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有改路径访问权限");

                                }
                            }
                        }
                        catch
                        {
                        }

                    }
                    else if (DateTransfer.AddIccByType == 3)
                    {
                        //LEADTOOLS加载ICC

                        //LEADTOOLS加载ICC


                        try
                        {

                            //IccProfileExtended iccProfile = new IccProfileExtended();

                            //// load the ICC from an image, by specifying the image's name, and the 1-based page number that contains the ICC. 
                            //// to load the ICC from an Image that is in a stream, put the stream instead of the file name. 
                            //iccProfile.ReadFromImage(@"E:\开单目录\back-wall-ms  山富灯片ok曲线\25.5x17.4x25.tif", 1);

                            //// at this point, the iccProfile object contains the ICC profile that was found in the image, 
                            //// you can use it as you want, but for this example, we will save it in a seperate ICC profile file. 
                            //// generate the profileId. For the time being, it will be filled with 0's 
                            //iccProfile.GenerateProfileId();

                            //// finally generate the new Icc Profile by updating the Data Array 
                            //// and then generating the file 
                            //iccProfile.UpdateDataArray();
                            switch (PicFormat)
                            {
                                case 0: codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Jpeg, 24);
                                    break;
                                case 1:
                                    codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Tif, 24);
                                    break;
                            }
                            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                            //IccProfileExtended iccP=new IccProfileExtended((
                            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                        }
                        catch (Exception ef)
                        {

                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }



                    }
                    else
                    {



                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                                break;
                        }


                    }
                }
                else//不需要加载ICC，则直接保存
                {


                    switch (PicFormat)
                    {
                        case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }
                }

                #region //写入ICC文件

                //UPTLab("正在加载ICC文件..." + board.IccPath);
                //if (!string.IsNullOrEmpty(board.IccPath))
                //{
                //    if (DateTransfer.AddIccByPs)//需要用PS加载ICC
                //    {
                //        try
                //        {
                //            //iCC的名称，需要与PS中的一致
                //            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                //            iccName = iccName.Substring(0, iccName.IndexOf("."));
                //            try
                //            {
                //                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                //            }
                //            catch { }
                //            string strPicFormat = "JPEG";
                //            string strInputIcc = "ColorMatch RGB";
                //            int intRatate = 0;
                //            if (board.IsTransverse)//竖向的就转90
                //                intRatate = -90;
                //            PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                //            //MessageBox.Show("请查看"+strTempPath+"是否有图片");
                //            string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);

                //            if (strResult == destFileName)
                //            {
                //                //MessageBox.Show("保存到" + destFileName);
                //                UPTLab("成功加载ICC文件!");
                //            }
                //            else
                //            {
                //                //MessageBox.Show("加载失败了！");
                //                //加载ICC失败
                //                UPTLab("加载ICC文件失败!" + strResult);
                //            }
                //        }
                //        catch (Exception ex)
                //        {
                //            throw new Exception("加载ICC文件错误" + ex.Message);
                //        }
                //        finally
                //        {
                //            try
                //            {
                //                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                //            }
                //            catch { }
                //        }
                //    }
                //    else   //用LEADTOOLS加载ICC
                //    {
                //        try
                //        {
                //            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                //            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                //        }
                //        catch (Exception ef)
                //        {
                //            UPTLab("加载ICC文件错误:" + ef.Message);
                //            throw new Exception("加载ICC文件错误" + ef.Message);
                //        }
                //    }
                //}
                #endregion


                destImage.Dispose();


                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                board.BoardBaseInfo.PicPath = destFileName;
                _mainBLL.MakeBigPicSusscess(board);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString());


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //_mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                int boardstatus = _mainBLL.SetBoardStatus2(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                if (boardstatus == 0)
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":无法修改Board状态，如有必要手动删除版" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                else
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                UPTLabBoardErrorList();
            }
            finally
            {
                errText = "";
            }
        }
        /// <summary>
        /// 横向生成大板并且裁切信息在照片前面
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2HCutBeforePic(BoardInfo_MakeBigPic board)
        {
            int XExcursion = 0;//X坐标偏移量
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            //int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            //int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素

            //XExcursion = boardPixWidth;
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸
            if (DateTransfer.SaveFileType == 1)
            {
                PicFormat = 1;
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            else
            {
                PicFormat = 0;
            }
            DateTransfer.IsAutoCut = board.IsTransverse;//已经用作是否裁切

            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {

                RasterCodecs codecs = new RasterCodecs();
                string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)BoardPixHeight / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                RasterImage smallBottom = null;
                int offsetW = smallTop.Height;
                int destWidth = boardPixWidth + offsetW;
                if (DateTransfer.TwoCutFlag)
                {
                    destWidth += offsetW;
                    aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)BoardPixHeight / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", "", "");
                    smallBottom = codecs.Load(Application.StartupPath + "\\temBar.bmp");

                }



                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    //boardPixWidth + offsetW,//+1保证最右边的框线可以出来
                    destWidth,
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                Color backColor = DateTransfer.BackColor;

                FillCommand fcommand = new FillCommand();
                //fcommand.Color = new RasterColor(128, 128, 128);
                fcommand.Color = new RasterColor(backColor);

                fcommand.Run(destImage);


                RotateCommand rcCutInfo = new RotateCommand();//旋转条码图片               
                rcCutInfo.Angle = -90 * 100;
                rcCutInfo.FillColor = new RasterColor(255, 255, 255);
                rcCutInfo.Flags = RotateCommandFlags.Resize;
                rcCutInfo.Run(smallTop);

                if (DateTransfer.TwoCutFlag)
                {
                    rcCutInfo.Run(smallBottom);
                }


                //添加裁切信息

                CombineFastCommand cfctop = new CombineFastCommand();

                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                cfctop.Run(smallTop);

                if (DateTransfer.TwoCutFlag)
                {
                    cfctop.DestinationRectangle = new Rectangle(destWidth - offsetW, 0, smallBottom.Width, smallBottom.Height);
                    cfctop.Run(smallBottom);
                }
                UPTLab("渲染大图框架成功");
                foreach (var picInfo in board.PhotoS)
                {
                    UPTLab("正在添加小图:" + picInfo.BasePhotoInfo.PhotoId);
                    if (!File.Exists(picInfo.BasePhotoInfo.PicPath))
                    {
                        throw new Exception("文件未找到:" + picInfo.BasePhotoInfo.PicPath);
                    }
                    try
                    {
                        #region 将所有的小图都粘贴到大图上
                        // 根据加急级别以及是否清空等确定字体的颜色

                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        if (!string.IsNullOrEmpty(DateTransfer.RemarkKeysColor))
                        {
                            FontColor = GetRemarkColor(picInfo.BasePhotoInfo.PicPath);

                        }
                        RasterImage smallPicImage = CreatePicImgH(picInfo, codecs, board);//
                        DrowPicLine(ref smallPicImage, Color.Green);
                        UPTLab("正在合成中间图");
                        RasterImage midImageTmp = CreateMidImgH(picInfo);//带有条码的中间图是横版
                        //UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)


                        //是否有备注
                        if (picInfo.barCodeStatus != SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode)//有条码
                        {

                            Color backColorBarcode = new Color();
                            RasterImage barcodeImageTemp = CreateBarCodeImgV(picInfo, midImageTmp, board, out backColorBarcode);//条码图片的临时图片
                            if (DateTransfer.PhotoRemarkFlag == 0)
                            {

                            }
                            else
                            {
                                double gray = backColorBarcode.R * 0.299 + 0.587 * backColorBarcode.G + 0.114 * backColorBarcode.B;
                                if (gray >= 128)
                                {
                                    FontColor = Color.Black;
                                }
                                else
                                {
                                    FontColor = Color.White;
                                }
                                //FontColor = Color.FromArgb(255-backColorBarcode.R,255-backColorBarcode.G,255-backColorBarcode.B);
                            }
                            //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            //RasterImage ColorImgBlock = GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            RasterImage ColorImgBlock = DateTransfer.PhotoRemarkFlag == 0 ? GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId) : GetColorBlockTextBackcolor(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                            UPTLab("粘贴色块");
                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                             0,
                             0,
                             barcodeImageTemp.Width,
                             barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);


                            UPTLab("生成条码及文字");

                            #region 打印条码及文字信息
                            Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            g.SmoothingMode = SmoothingMode.None;
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            int recX = ColorImgBlock.Width + 5, recY = -2;
                            string Barcode = "";
                            string nullBar = " ";
                            SizeF sizeF;
                            if (DateTransfer.SelectBarCodeType == 1)
                            {
                                recX += 20;
                                //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                            }
                            else if (DateTransfer.SelectBarCodeType == 0)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                //if (IsNum(tempBarcode))
                                //{
                                //    Barcode = "*" + tempBarcode + "*";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                //else
                                //{
                                //    Barcode = "";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                Barcode = "*" + tempBarcode + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                            }
                            else if (DateTransfer.SelectBarCodeType == 3)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('『');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('』');
                                if (startIndex == -1 || endIndex == -1)
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }
                                else
                                {
                                    string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                    //if (IsNum(tempBarcode))
                                    //{
                                    //    Barcode = "*" + tempBarcode + "*";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    //else
                                    //{
                                    //    Barcode = "";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    Barcode = "*" + tempBarcode + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                                }
                            }
                            else
                            {
                                Barcode = "";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                            }

                            BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度
                            //BARCODEWIDTH = Convert.ToInt16(sizeF.Width / gFont.DpiX * board.BoardBaseInfo.DPI);



                            //色块就有50
                            //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                            {

                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);



                                processor.Draw3dText(g,
                                                    Barcode,
                                                    rc,
                                                    SpecialEffectsTextStyle.Normal,
                                                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                    0, /* horizontal  shadow position */
                                                    0, /* vertical shadow position */
                                                    Color.Black,/* text color, blue */
                                                    Color.White,/* shadow color, black */
                                                    Color.White, /* border color, white */
                                                    textBarFont3o92,
                                                    null);





                                recX += BARCODEWIDTH;


                            }
                            else
                            {

                            }


                            //写其文字信息

                            recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            string productName = "";
                            string leftProduct = "";
                            picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                            int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                            if (PIndex > 0)
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex);
                            }
                            else
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName;
                                leftProduct = "-";
                            }


                            string text = "";
                            try
                            {
                                text = GetBarCodeStringByCutsom(picInfo, board).Trim('\\');
                            }
                            catch
                            {

                            }
                            SizeF sizetextF = gFont.MeasureString(text, textFont);

                            StringFormat textFormat = new StringFormat();
                            textFormat.Alignment = StringAlignment.Near;
                            textFormat.LineAlignment = StringAlignment.Center;
                            textFormat.FormatFlags = StringFormatFlags.DisplayFormatControl;

                            //textFormat.
                            Rectangle rcFont = new Rectangle(recX, 2, barcodeImageTemp.Width - recX, BARCODEHEIDHT);


                            gFont.PageUnit = GraphicsUnit.Pixel;

                            string newText = text;
                            if (DateTransfer.TextAlignType == 0)//左
                            {
                                newText = text;
                            }
                            else if (DateTransfer.TextAlignType == 1)//右对齐
                            {
                                for (int m = 0; m < text.Length; m++)
                                {
                                    newText = text.Substring(m);

                                    SizeF sizenewtextF = gFont.MeasureString(newText, textFont, barcodeImageTemp.Width - recX, textFormat);

                                    if (sizenewtextF.Width <= (barcodeImageTemp.Width - recX) * gFont.DpiX / board.BoardBaseInfo.DPI)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                newText = text;
                                textFormat.Alignment = StringAlignment.Center;
                                textFormat.LineAlignment = StringAlignment.Center;
                            }


                            g.PageUnit = GraphicsUnit.Pixel;
                            g.DrawString(newText, textFont, new SolidBrush(FontColor), rcFont, textFormat);




                            g.Dispose();
                            //gFont.Dispose();
                            ColorImgBlock.Dispose();//释放色块的资源
                            #endregion

                            UPTLab("正在粘贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            Rectangle barCodeRec, picRec;
                            //注释：照片的barcode方向是相对于中间图的 是指条码在中间图的横方向还是竖方向
                            //DateTransfer.RemarkInPicRightOrLeft的方向是相对于原图的方向他跟照片的旋转有关系
                            //其中的Rectangle中的坐标位置是相对于中间图的
                            //照片旋转是顺时针旋转270度
                            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左相对于中间图的跟原图木有关系
                            {
                                if (!picInfo.IsWhirl)
                                {

                                    if (DateTransfer.RemarkInPicRightOrLeft == 1)//0为配置要求要在实际照片的的左方向打条码0为右1为左
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                    else//条码放右面
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIDHT, barcodeImageTemp.Height);

                                    }
                                }
                                else//照片是旋转过的此时条码方向还是在左右但
                                {
                                    //相对于照片照片的上下
                                    if (DateTransfer.RemarkInPicBottomOrTop == 1)//相对于照片下面的话就是打在中间图的右面
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                    else////默认0为下 1为上 相对于照片是上面的话就是打在中间图的左面
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);

                                    }
                                }

                            }
                            else  //0:条码放在上下的时候
                            {
                                if (!picInfo.IsWhirl)//条码打在中间图的上下方向原始照片方向没有改变
                                {
                                    if (DateTransfer.RemarkInPicBottomOrTop == 0)//默认0为下  1为上
                                    {
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                    }
                                    else//上
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                    }
                                }
                                else//原始方向改变顺时针旋转了270度
                                {
                                    if (DateTransfer.RemarkInPicRightOrLeft == 1)//约定 0为右1为左  打在原照片的右侧就是打在中间图的上方 
                                    {
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                    }
                                    else//打在原图的左边相当于打在中间图的下面
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                    }
                                }

                            }



                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            cfcBarcode.SourcePoint = Point.Empty;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.DestinationImage = midImageTmp;


                            //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                            //{
                            //    UPTLab("对条码进行锐化");
                            //    SharpenCommand command = new SharpenCommand();
                            //    command.Sharpness = 950;
                            //    command.Run(barcodeImageTemp);
                            //}

                            //UPTLab("贴条码");
                            //贴条码
                            cfcBarcode.DestinationRectangle = barCodeRec;
                            cfcBarcode.Run(barcodeImageTemp);

                            //UPTLab("贴图片");
                            //贴图片
                            cfcBarcode.DestinationRectangle = picRec;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.Run(smallPicImage);

                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片

                            #endregion

                        }
                        else//无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                                                               0,
                                                                               0,
                                                                               smallPicImage.Width,
                                                                               smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }
                        #endregion

                        UPTLab("正在绘制中间图边框");
                        #region //给中间图画边框
                        if (DateTransfer.IsPrintLine)
                        {
                            Graphics g2 = null;
                            try
                            {
                                //SpecialEffectsProcessor processor2 = new SpecialEffectsProcessor();
                                //g2 = midImageTmp.CreateGdiPlusGraphics().Graphics;

                                //Rectangle rcShape2 = new Rectangle(0, 0, midImageTmp.ImageWidth, midImageTmp.ImageHeight);


                                //processor2.Draw3dShape(g2,
                                //                         SpecialEffectsShape.Rectangle, /* star shape */
                                //                         rcShape2,  /* destination rectangle */
                                //                         Color.Black, /* background color, blue */
                                //                         null, /* use this to place an image in the background */
                                //                         rcShape2, /* display background rectangle */
                                //                         SpecialEffectsBackStyle.TranslucentTiledImage, /* style flags for 3D shape */
                                //                         Color.Black, /* foreground color, red */
                                //                         SpecialEffectsFillStyle.Transparent, /* foreground style */
                                //                         Color.Black, /* border color, red */
                                //                         SpecialEffectsBorderStyle.Solid, /* border style */
                                //                         BoardLineWidth, /* border width */
                                //                         Color.Black, /* inner band highlight color, white */
                                //                         Color.Black, /* inner band shadow color */
                                //                         SpecialEffectsInnerStyle.None, /* inner band style */
                                //                         0, /* inner band width */
                                //                         Color.Black, /* outer band highlight color, RED */
                                //                         Color.Black, /* outer band shadow color */
                                //                         SpecialEffectsOuterStyle.None,/* outer band style */
                                //                         0, /* outer band width */
                                //                         0, /* horizontal shadow position */
                                //                         0, /* vertical shadow position */
                                //                         Color.Black, /* shadow color, black */
                                //                         null);    /* no region handle */
                                DrowBordLine(ref midImageTmp);
                            }
                            catch (Exception Boardex)//如果添加边框出错就不添加
                            {
                                WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.BasePhotoInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                                DrowBordLine(ref midImageTmp);
                            }
                            finally
                            {
                                if (g2 != null)
                                {
                                    g2.Dispose();
                                }
                            }
                        }
                        #endregion
                        UPTLab("正在粘贴图片:ID" + picInfo.BasePhotoInfo.PhotoId + ",照片" + picInfo.BasePhotoInfo.PicPath);
                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }



                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                                                                        pointX + offsetW,//在大图上的坐标
                                                                        pointY,
                                                                        midImageTmp.Width,//长和宽
                                                                        midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (board.IsTransverse)//自动裁切模式IsTransverse 改为是否使用裁切选择项目
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();

                            photoP.X = board.BoardBaseInfo.Height - (pointY + midImageTmp.Height);
                            photoP.Y = pointX;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;

                            if (!picInfo.IsWhirl)
                            {
                                photoP.Angle = 0;
                            }
                            else
                            {
                                photoP.Angle = 90;
                            }
                            //计算DXF宽高
                            //SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.DxfContent);
                            //DxfObjecctInfo mindxfObjecctInfo =
                            //    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                            //DxfObjecctInfo maxdxfObjecctInfo =
                            //  SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                            //DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                            //DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                            //photoP.DXFWidth = maxPointer.X - minPointer.X;
                            //photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                            //photoP.DXFContent = picInfo.DxfContent;
                            if (!string.IsNullOrEmpty(picInfo.BasePhotoInfo.DXFFilePath))
                            {
                                SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.BasePhotoInfo.DXFContent);
                                DxfObjecctInfo mindxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                                DxfObjecctInfo maxdxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                                DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                                DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                                photoP.DXFWidth = maxPointer.X - minPointer.X;
                                photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                                photoP.DXFContent = picInfo.DxfContent;
                            }
                            else
                            {
                                photoP.DXFWidth = 0;
                                photoP.DXFHeigth = 0;
                                photoP.DXFContent = null;
                            }
                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.PhotoS.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.BasePhotoInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.BasePhotoInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;



                if (DateTransfer.CutMinPhotoNum == 0)
                {
                    //不处理
                }
                else
                {
                    if (board.PhotoS.Count <= DateTransfer.CutMinPhotoNum)
                    {
                        DateTransfer.IsAutoCut = false;
                    }
                    else
                    {
                        //不处理
                    }
                }


                //写入文件 
                StringBuilder sbWriter = new StringBuilder();
                //sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.DPI);
                sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.PrinterName.Trim());
                foreach (PhotoPoint pp in listPhotoInfoForCut)
                {
                    string mmy = (((double)pp.Y / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                    string mmX = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                    string mmWidth = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                    string mmheight = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");

                    string dxfFlag = "DXF";
                    string strWriter = "";
                    if (pp.DXFContent == null)
                    {
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                    }
                    else
                    {
                        string angleStr = pp.Angle.ToString();
                        string wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                        string hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                        string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", ";");
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                    hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                    }
                    sbWriter.AppendLine(strWriter);

                }
                string FileName = _curCutFileFullPath;
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                WrtieTextEn(sbWriter, FileName);
                EncryptionAndSave(board.BoardBaseInfo.BoardId, sbWriter);
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;

                if (board.AddSharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    SharpenCommand command = new SharpenCommand();
                    command.Sharpness = board.AddSharpen;
                    command.Run(destImage);
                }

                UPTLab("正在保存大图...");
                bool isNeedAddIcc = false;
                if (!string.IsNullOrEmpty(board.IccPath))
                {
                    if (board.IccPath.EndsWith(".icc") || board.IccPath.EndsWith(".icm"))
                    {
                        if (File.Exists(board.IccPath))
                        {
                            isNeedAddIcc = true;//只有当ICCPATH不为空字符串，则是以。ICC、ICM结尾的，且文件存在的才加ICC
                        }
                    }

                }
                if (DateTransfer.AddIccByType == 0)
                {
                    isNeedAddIcc = false;
                }
                if (isNeedAddIcc)//需要加载ICC
                {
                    if (DateTransfer.AddIccByType == 1)//需要用PS加载ICC
                    {
                        //先保存到本地,等加载好ICC时存到网络路径                  
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }

                        //再调用PS加载ICC
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                            }
                            catch { }
                            string strPicFormat = "JPEG";
                            //string strInputIcc = "ColorMatch RGB";
                            string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            if (board.IsTransverse)//竖向的就转90
                                intRatate = -90;
                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);


                            string strResult = psApp.AddICC(iccName, strTempPath, destFileName);

                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件错误" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                            }
                            catch { }
                        }
                    }
                    else if (DateTransfer.AddIccByType == 2)
                    {
                        //调用IccProcessEXE 加载ICC

                        string tamPath = Environment.GetEnvironmentVariable("TEMP");
                        strTempPath = tamPath + "\\abc.jpg";
                        string iccPath = tamPath + board.IccPath.Substring(board.IccPath.LastIndexOf("\\"));
                        string loadediccPath = tamPath + "\\def.jpg";
                        string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        string fromTempICC = tamPath + "\\sRGB Color Space Profile.icm";
                        string exePath = Application.StartupPath + "\\IccProcessEXE.exe";
                        if (File.Exists(strTempPath))
                        {
                            File.Delete(strTempPath);
                        }
                        if (File.Exists(loadediccPath))
                        {
                            File.Delete(loadediccPath);
                        }
                        if (!File.Exists(iccPath))
                        {
                            File.Copy(board.IccPath, iccPath);
                        }
                        if (!File.Exists(fromTempICC))
                        {
                            File.Copy(FromIcc, fromTempICC);
                        }
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }
                        string iccFile = "";
                        //string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        try
                        {
                            UPTLab("正在加载ICC:" + board.IccPath);

                            using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                            {
                                pExecuteEXE.StartInfo.FileName = exePath;
                                //pExecuteEXE.StartInfo.Arguments = @"c:\1410.jpg,c:\sRGB Color Space Profile.icm,c:\efg1.jpg,c:\dnp100305-003.icm,95";
                                // pExecuteEXE.StartInfo.Arguments = strTempPath + "," + fromTempICC + "," + loadediccPath + "," + iccPath + "," + 95;
                                pExecuteEXE.StartInfo.Arguments = strTempPath + "," + doubleQM + fromTempICC + doubleQM + "," + loadediccPath + "," + doubleQM + iccPath + doubleQM + "," + 95;
                                pExecuteEXE.Start();
                                pExecuteEXE.WaitForExit();
                            }

                            //iccFile = iccLoad.IccProcess(strTempPath, fromTempICC, loadediccPath, iccPath,"100");
                            //if (!loadediccPath.Equals(iccFile))
                            //{
                            //    UPTLab("加载ICC文件错误:");
                            //    throw new Exception("加载ICC文件错误");

                            //}
                            //else
                            //{
                            //    File.Copy(loadediccPath, destFileName);
                            //}
                            if (File.Exists(loadediccPath))
                            {
                                try
                                {
                                    File.Copy(loadediccPath, destFileName, true);
                                }
                                catch (Exception ex)
                                {
                                    UPTLab("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有路径访问权限");
                                    throw new Exception("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有改路径访问权限");

                                }
                            }
                        }
                        catch
                        {
                        }

                    }
                    else if (DateTransfer.AddIccByType == 3)
                    {//LEADTOOLS加载ICC


                        try
                        {

                            //IccProfileExtended iccProfile = new IccProfileExtended();

                            //// load the ICC from an image, by specifying the image's name, and the 1-based page number that contains the ICC. 
                            //// to load the ICC from an Image that is in a stream, put the stream instead of the file name. 
                            //iccProfile.ReadFromImage(@"E:\开单目录\back-wall-ms  山富灯片ok曲线\25.5x17.4x25.tif", 1);

                            //// at this point, the iccProfile object contains the ICC profile that was found in the image, 
                            //// you can use it as you want, but for this example, we will save it in a seperate ICC profile file. 
                            //// generate the profileId. For the time being, it will be filled with 0's 
                            //iccProfile.GenerateProfileId();

                            //// finally generate the new Icc Profile by updating the Data Array 
                            //// and then generating the file 
                            //iccProfile.UpdateDataArray();
                            switch (PicFormat)
                            {
                                case 0: codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Jpeg, 24);
                                    break;
                                case 1:
                                    codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Tif, 24);
                                    break;
                            }
                            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                            //IccProfileExtended iccP=new IccProfileExtended((
                            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                        }
                        catch (Exception ef)
                        {

                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }

                    }
                    else
                    {



                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                                break;
                        }


                    }
                }
                else//不需要加载ICC，则直接保存
                {


                    switch (PicFormat)
                    {
                        case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }
                }

                #region //写入ICC文件


                #endregion


                destImage.Dispose();


                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                board.BoardBaseInfo.PicPath = destFileName;
                _mainBLL.MakeBigPicSusscess(board);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString());


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                int boardstatus = _mainBLL.SetBoardStatus2(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                if (boardstatus == 0)
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":无法修改Board状态，如有必要手动删除版" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                else
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                UPTLabBoardErrorList();
            }
            finally
            {
                errText = "";
            }
        }
        /// <summary>
        /// 横向排横向生成裁切标记方后面
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2HCutAfterPic(BoardInfo_MakeBigPic board)
        {
            int XExcursion = 0;//X坐标偏移量
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            //int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            //int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素

            //XExcursion = boardPixWidth;
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸
            if (DateTransfer.SaveFileType == 1)
            {
                PicFormat = 1;
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            else
            {
                PicFormat = 0;
            }
            DateTransfer.IsAutoCut = board.IsTransverse;//已经用作是否裁切

            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {

                RasterCodecs codecs = new RasterCodecs();
                string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)BoardPixHeight / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                int offsetW = smallTop.Height;
                Point topFlag = new Point(boardPixWidth, 0);      //第一条裁切标位置
                Point bottomFlg = new Point(0, 0);                            //第二条裁切标位置

                RasterImage smallBottom = null;
                int photoOffset = 0;                  //照片在板上坐标的实际偏移量
                int destWidth = boardPixWidth + offsetW;
                if (DateTransfer.TwoCutFlag)
                {
                    photoOffset = offsetW;
                    destWidth += offsetW;

                    aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)BoardPixHeight / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", "", "");
                    smallBottom = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                    //offsetW = offsetW*2;

                    bottomFlg = new Point(0, 0);

                }
                topFlag = new Point(boardPixWidth - offsetW, 0);

                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    // boardPixWidth + offsetW//,//+1保证最右边的框线可以出来
                   destWidth,
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                Color backColor = DateTransfer.BackColor;

                FillCommand fcommand = new FillCommand();
                //fcommand.Color = new RasterColor(128, 128, 128);
                fcommand.Color = new RasterColor(backColor);

                fcommand.Run(destImage);


                RotateCommand rcCutInfo = new RotateCommand();//旋转条码图片               
                rcCutInfo.Angle = 90 * 100;
                rcCutInfo.FillColor = new RasterColor(255, 255, 255);
                rcCutInfo.Flags = RotateCommandFlags.Resize;
                rcCutInfo.Run(smallTop);


                //添加裁切信息

                CombineFastCommand cfctop = new CombineFastCommand();

                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                if (DateTransfer.TwoCutFlag)
                {
                    rcCutInfo.Run(smallBottom);

                    cfctop.DestinationRectangle = new Rectangle(0, 0, smallBottom.Width, smallBottom.Height);
                    cfctop.Run(smallBottom);
                }


                cfctop.DestinationRectangle = new Rectangle(topFlag.X, 0, smallTop.Width, smallTop.Height);
                cfctop.Run(smallTop);


                UPTLab("渲染大图框架成功");
                foreach (var picInfo in board.PhotoS)
                {
                    UPTLab("正在添加小图:" + picInfo.BasePhotoInfo.PhotoId);
                    if (!File.Exists(picInfo.BasePhotoInfo.PicPath))
                    {
                        throw new Exception("文件未找到:" + picInfo.BasePhotoInfo.PicPath);
                    }
                    try
                    {
                        #region 将所有的小图都粘贴到大图上
                        // 根据加急级别以及是否清空等确定字体的颜色

                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        if (!string.IsNullOrEmpty(DateTransfer.RemarkKeysColor))
                        {
                            FontColor = GetRemarkColor(picInfo.BasePhotoInfo.PicPath);

                        }
                        RasterImage smallPicImage = CreatePicImgH(picInfo, codecs, board);//
                        DrowPicLine(ref smallPicImage, Color.Green);
                        UPTLab("正在合成中间图");
                        RasterImage midImageTmp = CreateMidImgH(picInfo);//带有条码的中间图是竖版中间图
                        //UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)


                        //是否有备注
                        if (picInfo.barCodeStatus != SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode)//有条码
                        {

                            Color backColorBarcode = new Color();
                            RasterImage barcodeImageTemp = CreateBarCodeImgV(picInfo, midImageTmp, board, out backColorBarcode);//条码图片的临时图片
                            if (DateTransfer.PhotoRemarkFlag == 0)
                            {

                            }
                            else
                            {
                                double gray = backColorBarcode.R * 0.299 + 0.587 * backColorBarcode.G + 0.114 * backColorBarcode.B;
                                if (gray >= 128)
                                {
                                    FontColor = Color.Black;
                                }
                                else
                                {
                                    FontColor = Color.White;
                                }
                                //FontColor = Color.FromArgb(255-backColorBarcode.R,255-backColorBarcode.G,255-backColorBarcode.B);
                            }
                            //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            //RasterImage ColorImgBlock = GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            RasterImage ColorImgBlock = DateTransfer.PhotoRemarkFlag == 0 ? GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId) : GetColorBlockTextBackcolor(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                            UPTLab("粘贴色块");
                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                             0,
                             0,
                             barcodeImageTemp.Width,
                             barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);


                            UPTLab("生成条码及文字");

                            #region 打印条码及文字信息
                            Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            g.SmoothingMode = SmoothingMode.None;
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            int recX = ColorImgBlock.Width + 5, recY = -2;
                            string Barcode = "";
                            string nullBar = " ";
                            SizeF sizeF;
                            if (DateTransfer.SelectBarCodeType == 1)
                            {
                                recX += 20;
                                //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                            }
                            else if (DateTransfer.SelectBarCodeType == 0)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);

                                Barcode = "*" + tempBarcode + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                            }
                            else if (DateTransfer.SelectBarCodeType == 3)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('『');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('』');
                                if (startIndex == -1 || endIndex == -1)
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }
                                else
                                {
                                    string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);

                                    Barcode = "*" + tempBarcode + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                                }
                            }
                            else
                            {
                                Barcode = "";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                            }

                            BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度
                            //BARCODEWIDTH = Convert.ToInt16(sizeF.Width / gFont.DpiX * board.BoardBaseInfo.DPI);



                            //色块就有50
                            //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                            {


                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);
                                processor.Draw3dText(g,
                                                    Barcode,
                                                    rc,
                                                    SpecialEffectsTextStyle.Normal,
                                                    SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                    0, /* horizontal  shadow position */
                                                    0, /* vertical shadow position */
                                                    Color.Black,/* text color, blue */
                                                    Color.White,/* shadow color, black */
                                                    Color.White, /* border color, white */
                                                    textBarFont3o92,
                                                    null);


                                recX += BARCODEWIDTH;


                            }
                            else
                            {

                            }                                                                                                                          //ColorResolutionCommand command = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Rgb,
                            //                                    RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            //command.Run(barcodeImageTemp);

                            //写其文字信息

                            recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            string productName = "";
                            string leftProduct = "";
                            picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                            int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                            if (PIndex > 0)
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex);
                            }
                            else
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName;
                                leftProduct = "-";
                            }


                            string text = "";
                            try
                            {
                                text = GetBarCodeStringByCutsom(picInfo, board).Trim('\\');
                            }
                            catch
                            {

                            }
                            SizeF sizetextF = gFont.MeasureString(text, textFont);

                            StringFormat textFormat = new StringFormat();
                            textFormat.Alignment = StringAlignment.Near;
                            textFormat.LineAlignment = StringAlignment.Center;
                            textFormat.FormatFlags = StringFormatFlags.DisplayFormatControl;

                            //textFormat.
                            Rectangle rcFont = new Rectangle(recX, 2, barcodeImageTemp.Width - recX, BARCODEHEIDHT);

                            gFont.PageUnit = GraphicsUnit.Pixel;

                            string newText = text;
                            if (DateTransfer.TextAlignType == 0)//左
                            {
                                newText = text;
                            }
                            else if (DateTransfer.TextAlignType == 1)//右对齐
                            {
                                for (int m = 0; m < text.Length; m++)
                                {
                                    newText = text.Substring(m);

                                    SizeF sizenewtextF = gFont.MeasureString(newText, textFont, barcodeImageTemp.Width - recX, textFormat);

                                    if (sizenewtextF.Width <= (barcodeImageTemp.Width - recX) * gFont.DpiX / board.BoardBaseInfo.DPI)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                newText = text;
                                textFormat.Alignment = StringAlignment.Center;
                                textFormat.LineAlignment = StringAlignment.Center;
                            }


                            g.PageUnit = GraphicsUnit.Pixel;
                            g.DrawString(newText, textFont, new SolidBrush(FontColor), rcFont, textFormat);




                            g.Dispose();
                            //gFont.Dispose();
                            ColorImgBlock.Dispose();//释放色块的资源
                            #endregion

                            UPTLab("正在粘贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            Rectangle barCodeRec, picRec;

                            //注释：照片的barcode方向是相对于中间图的 是指条码在中间图的横方向还是竖方向
                            //DateTransfer.RemarkInPicRightOrLeft的方向是相对于原图的方向他跟照片的旋转有关系
                            //其中的Rectangle中的坐标位置是相对于中间图的
                            //照片旋转是顺时针旋转270度
                            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左相对于中间图的跟原图木有关系
                            {
                                if (!picInfo.IsWhirl)
                                {

                                    if (DateTransfer.RemarkInPicRightOrLeft == 1)//0为配置要求要在实际照片的的左方向打条码0为右1为左
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                    else//条码放右面
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIDHT, barcodeImageTemp.Height);

                                    }
                                }
                                else//照片是旋转过的此时条码方向还是在左右但
                                {
                                    //相对于照片照片的上下
                                    if (DateTransfer.RemarkInPicBottomOrTop == 1)//相对于照片下面的话就是打在中间图的右面
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                    }
                                    else////默认0为下 1为上 相对于照片是上面的话就是打在中间图的左面
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);

                                    }
                                }

                            }
                            else  //0:条码放在上下的时候
                            {
                                if (!picInfo.IsWhirl)//条码打在中间图的上下方向原始照片方向没有改变
                                {
                                    if (DateTransfer.RemarkInPicBottomOrTop == 0)//默认0为下  1为上
                                    {
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                    }
                                    else//上
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                    }
                                }
                                else//原始方向改变顺时针旋转了270度
                                {
                                    if (DateTransfer.RemarkInPicRightOrLeft == 1)//约定 0为右1为左  打在原照片的右侧就是打在中间图的上方 
                                    {
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                    }
                                    else//打在原图的左边相当于打在中间图的下面
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                    }
                                }

                            }
                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            cfcBarcode.SourcePoint = Point.Empty;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.DestinationImage = midImageTmp;


                            //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                            //{
                            //    UPTLab("对条码进行锐化");
                            //    SharpenCommand command = new SharpenCommand();
                            //    command.Sharpness = 950;
                            //    command.Run(barcodeImageTemp);
                            //}

                            //UPTLab("贴条码");
                            //贴条码
                            cfcBarcode.DestinationRectangle = barCodeRec;
                            cfcBarcode.Run(barcodeImageTemp);

                            //UPTLab("贴图片");
                            //贴图片
                            cfcBarcode.DestinationRectangle = picRec;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.Run(smallPicImage);

                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                            #endregion

                        }
                        else//无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                                                               0,
                                                                               0,
                                                                               smallPicImage.Width,
                                                                               smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }
                        #endregion

                        UPTLab("正在绘制中间图边框");
                        #region //给中间图画边框
                        if (DateTransfer.IsPrintLine)
                        {
                            Graphics g2 = null;
                            try
                            {

                                DrowBordLine(ref midImageTmp);
                            }
                            catch (Exception Boardex)//如果添加边框出错就不添加
                            {
                                WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.BasePhotoInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                                DrowBordLine(ref midImageTmp);
                            }
                            finally
                            {
                                if (g2 != null)
                                {
                                    g2.Dispose();
                                }
                            }
                        }
                        #endregion
                        UPTLab("正在粘贴图片:ID" + picInfo.BasePhotoInfo.PhotoId + ",照片" + picInfo.BasePhotoInfo.PicPath);
                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }



                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                                                                        pointX + photoOffset,//在大图上的坐标
                                                                        pointY,
                                                                        midImageTmp.Width,//长和宽
                                                                        midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (board.IsTransverse)//自动裁切模式IsTransverse 改为是否使用裁切选择项目
                        {

                            PhotoPoint photoP = new PhotoPoint();

                            photoP.X = pointY;
                            photoP.Y = board.BoardBaseInfo.Length - (pointX + midImageTmp.Width);
                            if (photoP.Y < 0)
                            {
                                photoP.Y = 0;
                            }
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;

                            if (picInfo.IsWhirl)
                            {
                                photoP.Angle = 180;
                            }
                            else
                            {
                                photoP.Angle = 270;
                            }
                            //计算DXF宽高
                            //SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.DxfContent);
                            //DxfObjecctInfo mindxfObjecctInfo =
                            //    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                            //DxfObjecctInfo maxdxfObjecctInfo =
                            //  SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                            //DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                            //DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                            //photoP.DXFWidth = maxPointer.X - minPointer.X;
                            //photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                            //photoP.DXFContent = picInfo.DxfContent;

                            if (!string.IsNullOrEmpty(picInfo.BasePhotoInfo.DXFFilePath))
                            {
                                SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.BasePhotoInfo.DXFContent);
                                DxfObjecctInfo mindxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                                DxfObjecctInfo maxdxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                                DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                                DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                                photoP.DXFWidth = maxPointer.X - minPointer.X;
                                photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                                photoP.DXFContent = picInfo.DxfContent;
                            }
                            else
                            {
                                photoP.DXFWidth = 0;
                                photoP.DXFHeigth = 0;
                                photoP.DXFContent = null;
                            }

                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.PhotoS.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.BasePhotoInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.BasePhotoInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;



                if (DateTransfer.CutMinPhotoNum == 0)
                {
                    //不处理
                }
                else
                {
                    if (board.PhotoS.Count <= DateTransfer.CutMinPhotoNum)
                    {
                        DateTransfer.IsAutoCut = false;
                    }
                    else
                    {
                        //不处理
                    }
                }


                //写入文件 
                StringBuilder sbWriter = new StringBuilder();
                //sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.DPI);
                sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.PrinterName.Trim());
                foreach (PhotoPoint pp in listPhotoInfoForCut)
                {
                    string mmX = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                    string mmy = (((double)pp.Y / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                    string mmWidth = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                    string mmheight = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                    string dxfFlag = "DXF";
                    string strWriter = "";
                    if (pp.DXFContent == null)
                    {
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                    }
                    else
                    {
                        string angleStr = pp.Angle.ToString();
                        string wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                        string hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                        string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", ";");
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                    hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                    }
                    sbWriter.AppendLine(strWriter);

                }
                string FileName = _curCutFileFullPath;
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                WrtieTextEn(sbWriter, FileName);
                EncryptionAndSave(board.BoardBaseInfo.BoardId, sbWriter);
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;

                if (board.AddSharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    SharpenCommand command = new SharpenCommand();
                    command.Sharpness = board.AddSharpen;
                    command.Run(destImage);
                }

                UPTLab("正在保存大图...");
                bool isNeedAddIcc = false;
                if (!string.IsNullOrEmpty(board.IccPath))
                {
                    if (board.IccPath.EndsWith(".icc") || board.IccPath.EndsWith(".icm"))
                    {
                        if (File.Exists(board.IccPath))
                        {
                            isNeedAddIcc = true;//只有当ICCPATH不为空字符串，则是以。ICC、ICM结尾的，且文件存在的才加ICC
                        }
                    }

                }
                if (DateTransfer.AddIccByType == 0)
                {
                    isNeedAddIcc = false;
                }
                if (isNeedAddIcc)//需要加载ICC
                {
                    if (DateTransfer.AddIccByType == 1)//需要用PS加载ICC
                    {
                        //先保存到本地,等加载好ICC时存到网络路径                  
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }

                        //再调用PS加载ICC
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                            }
                            catch { }
                            string strPicFormat = "JPEG";
                            //string strInputIcc = "ColorMatch RGB";
                            string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            if (board.IsTransverse)//竖向的就转90
                                intRatate = -90;
                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);

                            string strResult = psApp.AddICC(iccName, strTempPath, destFileName);


                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件错误" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                            }
                            catch { }
                        }
                    }
                    else if (DateTransfer.AddIccByType == 2)
                    {
                        //调用IccProcessEXE 加载ICC

                        string tamPath = Environment.GetEnvironmentVariable("TEMP");
                        strTempPath = tamPath + "\\abc.jpg";
                        string iccPath = tamPath + board.IccPath.Substring(board.IccPath.LastIndexOf("\\"));
                        string loadediccPath = tamPath + "\\def.jpg";
                        string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        string fromTempICC = tamPath + "\\sRGB Color Space Profile.icm";
                        string exePath = Application.StartupPath + "\\IccProcessEXE.exe";
                        if (File.Exists(strTempPath))
                        {
                            File.Delete(strTempPath);
                        }
                        if (File.Exists(loadediccPath))
                        {
                            File.Delete(loadediccPath);
                        }
                        if (!File.Exists(iccPath))
                        {
                            File.Copy(board.IccPath, iccPath);
                        }
                        if (!File.Exists(fromTempICC))
                        {
                            File.Copy(FromIcc, fromTempICC);
                        }
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }
                        string iccFile = "";
                        //string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        try
                        {
                            UPTLab("正在加载ICC:" + board.IccPath);

                            using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                            {
                                pExecuteEXE.StartInfo.FileName = exePath;
                                //pExecuteEXE.StartInfo.Arguments = @"c:\1410.jpg,c:\sRGB Color Space Profile.icm,c:\efg1.jpg,c:\dnp100305-003.icm,95";
                                //pExecuteEXE.StartInfo.Arguments = strTempPath + "," + fromTempICC + "," + loadediccPath + "," + iccPath + "," + 95;
                                pExecuteEXE.StartInfo.Arguments = strTempPath + "," + doubleQM + fromTempICC + doubleQM + "," + loadediccPath + "," + doubleQM + iccPath + doubleQM + "," + 95;
                                pExecuteEXE.Start();
                                pExecuteEXE.WaitForExit();
                            }

                            //iccFile = iccLoad.IccProcess(strTempPath, fromTempICC, loadediccPath, iccPath,"100");
                            //if (!loadediccPath.Equals(iccFile))
                            //{
                            //    UPTLab("加载ICC文件错误:");
                            //    throw new Exception("加载ICC文件错误");

                            //}
                            //else
                            //{
                            //    File.Copy(loadediccPath, destFileName);
                            //}
                            if (File.Exists(loadediccPath))
                            {
                                try
                                {
                                    File.Copy(loadediccPath, destFileName, true);
                                }
                                catch (Exception ex)
                                {
                                    UPTLab("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有路径访问权限");
                                    throw new Exception("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有改路径访问权限");

                                }
                            }
                        }
                        catch
                        {
                        }

                    }
                    else if (DateTransfer.AddIccByType == 3)
                    {
                        //LEADTOOLS加载ICC


                        try
                        {

                            //IccProfileExtended iccProfile = new IccProfileExtended();

                            //// load the ICC from an image, by specifying the image's name, and the 1-based page number that contains the ICC. 
                            //// to load the ICC from an Image that is in a stream, put the stream instead of the file name. 
                            //iccProfile.ReadFromImage(@"E:\开单目录\back-wall-ms  山富灯片ok曲线\25.5x17.4x25.tif", 1);

                            //// at this point, the iccProfile object contains the ICC profile that was found in the image, 
                            //// you can use it as you want, but for this example, we will save it in a seperate ICC profile file. 
                            //// generate the profileId. For the time being, it will be filled with 0's 
                            //iccProfile.GenerateProfileId();

                            //// finally generate the new Icc Profile by updating the Data Array 
                            //// and then generating the file 
                            //iccProfile.UpdateDataArray();
                            switch (PicFormat)
                            {
                                case 0: codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Jpeg, 24);
                                    break;
                                case 1:
                                    codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Tif, 24);
                                    break;
                            }
                            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                            //IccProfileExtended iccP=new IccProfileExtended((
                            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                        }
                        catch (Exception ef)
                        {

                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }


                    }
                    else
                    {



                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                                break;
                        }


                    }
                }
                else//不需要加载ICC，则直接保存
                {


                    switch (PicFormat)
                    {
                        case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }
                }

                #region //写入ICC文件


                #endregion


                destImage.Dispose();


                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                board.BoardBaseInfo.PicPath = destFileName;
                _mainBLL.MakeBigPicSusscess(board);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString());


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                int boardstatus = _mainBLL.SetBoardStatus2(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                if (boardstatus == 0)
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":无法修改Board状态，如有必要手动删除版" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                else
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                UPTLabBoardErrorList();
            }
            finally
            {
                errText = "";
            }
        }

        private void DrowBordLine(ref  RasterImage rstImg)
        {
            Color BackLine = DateTransfer.LineBack;
            //RasterCodecs codecs = new RasterCodecs();
            RasterImage leftLine = new RasterImage(
                              RasterMemoryFlags.Conventional,
                              1,//+1保证最右边的框线可以出来
                              rstImg.Height,
                              24,
                              RasterByteOrder.Bgr,
                              RasterViewPerspective.BottomLeft,
                              null,
                              IntPtr.Zero,
                              0);
            FillCommand fcommandW = new FillCommand();
            fcommandW.Color = new RasterColor(BackLine.R, BackLine.G, BackLine.B);
            fcommandW.Run(leftLine);
            RasterImage RightLine = new RasterImage(
                             RasterMemoryFlags.Conventional,
                             1,//+1保证最右边的框线可以出来
                             rstImg.Height,
                             24,
                             RasterByteOrder.Bgr,
                             RasterViewPerspective.BottomLeft,
                             null,
                             IntPtr.Zero,
                             0);

            fcommandW.Color = new RasterColor(BackLine.R, BackLine.G, BackLine.B);
            fcommandW.Run(RightLine);
            RasterImage TopLine = new RasterImage(
                            RasterMemoryFlags.Conventional,
                            rstImg.Width,//+1保证最右边的框线可以出来
                            1,
                            24,
                            RasterByteOrder.Bgr,
                            RasterViewPerspective.BottomLeft,
                            null,
                            IntPtr.Zero,
                            0);
            fcommandW.Color = new RasterColor(BackLine.R, BackLine.G, BackLine.B);
            fcommandW.Run(TopLine);
            RasterImage BottomLine = new RasterImage(
                            RasterMemoryFlags.Conventional,
                            rstImg.Width,//+1保证最右边的框线可以出来
                            1,
                            24,
                            RasterByteOrder.Bgr,
                            RasterViewPerspective.BottomLeft,
                            null,
                            IntPtr.Zero,
                            0);
            fcommandW.Color = new RasterColor(BackLine.R, BackLine.G, BackLine.B);
            fcommandW.Run(BottomLine);
            CombineFastCommand cfcLine = new CombineFastCommand();
            cfcLine.SourcePoint = Point.Empty;
            cfcLine.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            cfcLine.DestinationImage = rstImg;

            cfcLine.DestinationRectangle = new Rectangle(0, 0, leftLine.Width, leftLine.Height);
            cfcLine.Run(leftLine);

            cfcLine.DestinationRectangle = new Rectangle(rstImg.Width - 1, 0, RightLine.Width, RightLine.Height);
            cfcLine.Run(RightLine);

            cfcLine.DestinationRectangle = new Rectangle(0, 0, TopLine.Width, TopLine.Height);
            cfcLine.Run(TopLine);

            cfcLine.DestinationRectangle = new Rectangle(0, rstImg.Height - 1, BottomLine.Width, BottomLine.Height);
            cfcLine.Run(BottomLine);



        }
        private void DrowPicLine(ref  RasterImage rstImg, Color lineColor)
        {
            //RasterCodecs codecs = new RasterCodecs();
            RasterImage leftLine = new RasterImage(
                              RasterMemoryFlags.Conventional,
                              1,//+1
                              rstImg.Height,
                              24,
                              RasterByteOrder.Bgr,
                              RasterViewPerspective.BottomLeft,
                              null,
                              IntPtr.Zero,
                              0);
            FillCommand fcommandW = new FillCommand();
            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(leftLine);
            RasterImage RightLine = new RasterImage(
                             RasterMemoryFlags.Conventional,
                             1,//+1
                             rstImg.Height,
                             24,
                             RasterByteOrder.Bgr,
                             RasterViewPerspective.BottomLeft,
                             null,
                             IntPtr.Zero,
                             0);

            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(RightLine);
            RasterImage TopLine = new RasterImage(
                            RasterMemoryFlags.Conventional,
                            rstImg.Width,//+1
                            1,
                            24,
                            RasterByteOrder.Bgr,
                            RasterViewPerspective.BottomLeft,
                            null,
                            IntPtr.Zero,
                            0);
            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(TopLine);
            RasterImage BottomLine = new RasterImage(
                            RasterMemoryFlags.Conventional,
                            rstImg.Width,//+1
                            1,
                            24,
                            RasterByteOrder.Bgr,
                            RasterViewPerspective.BottomLeft,
                            null,
                            IntPtr.Zero,
                            0);
            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(BottomLine);
            CombineFastCommand cfcLine = new CombineFastCommand();
            cfcLine.SourcePoint = Point.Empty;
            cfcLine.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            cfcLine.DestinationImage = rstImg;

            cfcLine.DestinationRectangle = new Rectangle(0, 0, leftLine.Width, leftLine.Height);
            cfcLine.Run(leftLine);

            cfcLine.DestinationRectangle = new Rectangle(rstImg.Width - 1, 0, RightLine.Width, RightLine.Height);
            cfcLine.Run(RightLine);

            cfcLine.DestinationRectangle = new Rectangle(0, 0, TopLine.Width, TopLine.Height);
            cfcLine.Run(TopLine);

            cfcLine.DestinationRectangle = new Rectangle(0, rstImg.Height - 1, BottomLine.Width, BottomLine.Height);
            cfcLine.Run(BottomLine);



        }
        public static bool IsNum(String str)
        {
            for (int i = 0; i < str.Length; i++)
            {
                if (!Char.IsNumber(str, i))
                    return false;
            }
            return true;
        }
        private void MakeBigPicV2(BoardInfo_MakeBigPic board)
        {
            int XExcursion = 0;//X坐标偏移量
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            //int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            //int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素

            //XExcursion = boardPixWidth;
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸
            if (DateTransfer.SaveFileType == 1)
            {
                PicFormat = 1;
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            else
            {
                PicFormat = 0;
            }
            DateTransfer.IsAutoCut = board.IsTransverse;//已经用作是否裁切

            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {

                RasterCodecs codecs = new RasterCodecs();
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    boardPixWidth,//+1保证最右边的框线可以出来
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                Color backColor = DateTransfer.BackColor;

                FillCommand fcommand = new FillCommand();
                //fcommand.Color = new RasterColor(128, 128, 128);
                fcommand.Color = new RasterColor(backColor);

                fcommand.Run(destImage);

                UPTLab("渲染大图框架成功");
                foreach (var picInfo in board.PhotoS)
                {
                    UPTLab("正在添加小图:" + picInfo.BasePhotoInfo.PhotoId);
                    if (!File.Exists(picInfo.BasePhotoInfo.PicPath))
                    {
                        throw new Exception("文件未找到:" + picInfo.BasePhotoInfo.PicPath);
                    }
                    try
                    {
                        #region 将所有的小图都粘贴到大图上
                        // 根据加急级别以及是否清空等确定字体的颜色

                        Color FontColor = GetFontColorByPhotoInfo(picInfo);


                        if (!string.IsNullOrEmpty(DateTransfer.RemarkKeysColor))
                        {
                            FontColor = GetRemarkColor(picInfo.BasePhotoInfo.PicPath);

                        }
                        RasterImage smallPicImage = CreatePicImgH(picInfo, codecs, board);//
                        DrowPicLine(ref smallPicImage, Color.Green);
                        UPTLab("正在合成中间图");
                        RasterImage midImageTmp = CreateMidImgH(picInfo);//带有条码的中间图是竖版中间图
                        //UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)


                        //是否有备注
                        if (picInfo.barCodeStatus != SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode)//有条码
                        {

                            Color backColorBarcode = new Color();
                            RasterImage barcodeImageTemp = CreateBarCodeImgV(picInfo, midImageTmp, board, out backColorBarcode);//条码图片的临时图片
                            if (DateTransfer.PhotoRemarkFlag == 0)
                            {

                            }
                            else
                            {
                                double gray = backColorBarcode.R * 0.299 + 0.587 * backColorBarcode.G + 0.114 * backColorBarcode.B;
                                if (gray >= 128)
                                {
                                    FontColor = Color.Black;
                                }
                                else
                                {
                                    FontColor = Color.White;
                                }
                                //FontColor = Color.FromArgb(255-backColorBarcode.R,255-backColorBarcode.G,255-backColorBarcode.B);
                            }
                            //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            //RasterImage ColorImgBlock = GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            RasterImage ColorImgBlock = DateTransfer.PhotoRemarkFlag == 0 ? GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId) : GetColorBlockTextBackcolor(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                            UPTLab("粘贴色块");
                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                             0,
                             0,
                             barcodeImageTemp.Width,
                             barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);


                            UPTLab("生成条码及文字");

                            #region 打印条码及文字信息
                            Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            g.SmoothingMode = SmoothingMode.None;
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            int recX = ColorImgBlock.Width + 5, recY = -2;
                            string Barcode = "";
                            string nullBar = " ";
                            SizeF sizeF;
                            if (DateTransfer.SelectBarCodeType == 1)
                            {
                                recX += 20;
                                //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                            }
                            else if (DateTransfer.SelectBarCodeType == 0)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                //if (IsNum(tempBarcode))
                                //{
                                //    Barcode = "*" + tempBarcode + "*";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                //else
                                //{
                                //    Barcode = "";
                                //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                //}
                                Barcode = "*" + tempBarcode + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o9);

                            }
                            else if (DateTransfer.SelectBarCodeType == 3)
                            {
                                recX += 20;
                                int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('『');
                                int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('』');
                                if (startIndex == -1 || endIndex == -1)
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }
                                else
                                {
                                    string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                    //if (IsNum(tempBarcode))
                                    //{
                                    //    Barcode = "*" + tempBarcode + "*";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    //else
                                    //{
                                    //    Barcode = "";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    Barcode = "*" + tempBarcode + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                                }
                            }

                            else
                            {
                                Barcode = "";
                                sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                            }

                            BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度
                            //BARCODEWIDTH = Convert.ToInt16(sizeF.Width / gFont.DpiX * board.BoardBaseInfo.DPI);



                            //色块就有50
                            //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                //g.DrawString (Brushes

                                processor.Draw3dShape(g, SpecialEffectsShape.Rectangle, rc, Color.White, null, rc, SpecialEffectsBackStyle.Opaque, Color.White, SpecialEffectsFillStyle.Solid, Color.White, SpecialEffectsBorderStyle.Solid, 0, Color.White, Color.White, SpecialEffectsInnerStyle.None, 0, Color.White, Color.White, SpecialEffectsOuterStyle.None, 0, 0, 0, Color.White, null);

                                processor.Draw3dText(g,
                                                   Barcode,
                                                     rc,
                                                     SpecialEffectsTextStyle.Normal,
                                                     SpecialEffectsTextAlignmentFlags.HorizontalCenter | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                     0, /* horizontal  shadow position */
                                                     0, /* vertical shadow position */
                                                     Color.Black, /* text color, blue */
                                                     backColorBarcode,/* shadow color, black */
                                                     backColorBarcode, /* border color, white */
                                                     DateTransfer.SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o9,
                                                     null);
                                //StringFormat barFormat = new StringFormat();
                                //barFormat.Alignment = StringAlignment.Center;

                                ////barFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap | StringFormatFlags.DirectionRightToLeft;
                                //barFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;

                                //barFormat.LineAlignment = StringAlignment.Center;
                                ////Rectangle rcBarcode = new Rectangle(rc.X, rc.Y, Convert.ToInt16(rc.Width / gFont.DpiX * board.BoardBaseInfo.DPI), Convert.ToInt16(rc.Height / gFont.DpiX * board.BoardBaseInfo.DPI));
                                //g.DrawString(Barcode, DateTransfer.SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o92, new SolidBrush(Color.Black), rc, barFormat);
                                //g.DrawString("123", textFont, new SolidBrush(Color.Black), rc,barFormat);

                                recX += BARCODEWIDTH;
                            }
                            else
                            {

                            }


                            //写其文字信息

                            recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            string productName = "";
                            string leftProduct = "";
                            picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                            int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                            if (PIndex > 0)
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex);
                            }
                            else
                            {
                                productName = picInfo.BasePhotoInfo.PhotoName;
                                leftProduct = "-";
                            }

                            //SpecialEffectsTextAlignmentFlags alignHorizontal = SpecialEffectsTextAlignmentFlags.Left;
                            //if (TextAlignType == 0)
                            //{
                            //    alignHorizontal = SpecialEffectsTextAlignmentFlags.Left;

                            //}
                            //else if (TextAlignType == 1)
                            //{
                            //    alignHorizontal = SpecialEffectsTextAlignmentFlags.Right;
                            //}
                            //else
                            //{
                            //    alignHorizontal = SpecialEffectsTextAlignmentFlags.HorizontalCenter;
                            //}
                            string text = "";
                            try
                            {
                                text = GetBarCodeStringByCutsom(picInfo, board).Trim('\\');
                            }
                            catch
                            {

                            }
                            SizeF sizetextF = gFont.MeasureString(text, textFont);

                            StringFormat textFormat = new StringFormat();
                            textFormat.Alignment = StringAlignment.Near;
                            textFormat.LineAlignment = StringAlignment.Center;
                            textFormat.FormatFlags = StringFormatFlags.DisplayFormatControl;

                            //textFormat.
                            Rectangle rcFont = new Rectangle(recX, 2, barcodeImageTemp.Width - recX, BARCODEHEIDHT);

                            //processor.Draw3dText(g,
                            //                    text,
                            //                    rcFont,
                            //                    SpecialEffectsTextStyle.Normal,
                            //                    alignHorizontal | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                            //                    0, /* horizontal  shadow position */
                            //                    0, /* vertical shadow position */
                            //                    FontColor,/* text color, blue */
                            //                    backColorBarcode,/* shadow color, black */
                            //                    backColorBarcode, /* border color, white */
                            //                    textFont,
                            //                    null);
                            gFont.PageUnit = GraphicsUnit.Pixel;

                            string newText = text;
                            if (DateTransfer.TextAlignType == 0)//左
                            {
                                newText = text;
                            }
                            else if (DateTransfer.TextAlignType == 1)//右对齐
                            {
                                for (int m = 0; m < text.Length; m++)
                                {
                                    newText = text.Substring(m);

                                    SizeF sizenewtextF = gFont.MeasureString(newText, textFont, barcodeImageTemp.Width - recX, textFormat);

                                    if (sizenewtextF.Width <= (barcodeImageTemp.Width - recX) * gFont.DpiX / board.BoardBaseInfo.DPI)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                newText = text;
                                textFormat.Alignment = StringAlignment.Center;
                                textFormat.LineAlignment = StringAlignment.Center;
                            }


                            g.PageUnit = GraphicsUnit.Pixel;
                            g.DrawString(newText, textFont, new SolidBrush(FontColor), rcFont, textFormat);




                            g.Dispose();
                            //gFont.Dispose();
                            ColorImgBlock.Dispose();//释放色块的资源
                            #endregion

                            UPTLab("正在粘贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            Rectangle barCodeRec, picRec;

                            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左
                            {
                                RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                rcBarcode.Angle = 270 * 100;
                                rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                rcBarcode.Flags = RotateCommandFlags.Resize;
                                rcBarcode.Run(barcodeImageTemp);


                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                            }
                            else  //0:条码放在下面
                            {
                                barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, BARCODEHEIDHT);
                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);

                            }

                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            cfcBarcode.SourcePoint = Point.Empty;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.DestinationImage = midImageTmp;


                            //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                            //{
                            //    UPTLab("对条码进行锐化");
                            //    SharpenCommand command = new SharpenCommand();
                            //    command.Sharpness = 950;
                            //    command.Run(barcodeImageTemp);
                            //}

                            //UPTLab("贴条码");
                            //贴条码
                            cfcBarcode.DestinationRectangle = barCodeRec;
                            cfcBarcode.Run(barcodeImageTemp);

                            //UPTLab("贴图片");
                            //贴图片
                            cfcBarcode.DestinationRectangle = picRec;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.Run(smallPicImage);

                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                            #endregion

                        }
                        else//无条码
                        {
                            if (DateTransfer.IsPrintBarCodeInPicture)
                            {

                                Color backColorBarcode = new Color();
                                RasterImage barcodeImageTemp = CreateBarCodeImgV(picInfo, midImageTmp, board, out backColorBarcode);//条码图片的临时图片
                                if (DateTransfer.PhotoRemarkFlag == 0)
                                {

                                }
                                else
                                {
                                    double gray = backColorBarcode.R * 0.299 + 0.587 * backColorBarcode.G + 0.114 * backColorBarcode.B;
                                    if (gray >= 128)
                                    {
                                        FontColor = Color.Black;
                                    }
                                    else
                                    {
                                        FontColor = Color.White;
                                    }
                                    //FontColor = Color.FromArgb(255-backColorBarcode.R,255-backColorBarcode.G,255-backColorBarcode.B);
                                }
                                //RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                                //RasterImage ColorImgBlock = GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                                RasterImage ColorImgBlock = DateTransfer.PhotoRemarkFlag == 0 ? GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId) : GetColorBlockTextBackcolor(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                                UPTLab("粘贴色块");
                                CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                                cfcBarcode1.DestinationRectangle = new Rectangle(
                                 0,
                                 0,
                                 barcodeImageTemp.Width,
                                 barcodeImageTemp.Height);

                                cfcBarcode1.SourcePoint = Point.Empty;
                                cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                                cfcBarcode1.DestinationImage = barcodeImageTemp;
                                cfcBarcode1.Run(ColorImgBlock);


                                UPTLab("生成条码及文字");

                                #region 打印条码及文字信息
                                Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                                g.SmoothingMode = SmoothingMode.None;
                                SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                                int recX = ColorImgBlock.Width + 5, recY = -2;
                                string Barcode = "";
                                string nullBar = " ";
                                SizeF sizeF;
                                if (DateTransfer.SelectBarCodeType == 1)
                                {
                                    recX += 20;
                                    //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                                    //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                    Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                                }
                                else if (DateTransfer.SelectBarCodeType == 0)
                                {
                                    recX += 20;
                                    int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                                    int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                                    string tempBarcode = picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1);
                                    //if (IsNum(tempBarcode))
                                    //{
                                    //    Barcode = "*" + tempBarcode + "*";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    //else
                                    //{
                                    //    Barcode = "";
                                    //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                    //}
                                    Barcode = "*" + tempBarcode + "*";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);
                                }
                                else
                                {
                                    Barcode = "";
                                    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                                }

                                BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度
                                //BARCODEWIDTH = Convert.ToInt16(sizeF.Width / gFont.DpiX * board.BoardBaseInfo.DPI);
                                // BARCODEWIDTH = BARCODEWIDTH * 2;


                                //色块就有50
                                //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                                if (DateTransfer.MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                                {
                                    //////打条码
                                    ////Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                    //////g.DrawString (Brushes

                                    ////processor.Draw3dShape(g, SpecialEffectsShape.Rectangle, rc, Color.White, null, rc, SpecialEffectsBackStyle.Opaque, Color.White, SpecialEffectsFillStyle.Solid, Color.White, SpecialEffectsBorderStyle.Solid, 0, Color.White, Color.White, SpecialEffectsInnerStyle.None, 0, Color.White, Color.White, SpecialEffectsOuterStyle.None, 0, 0, 0, Color.White, null);

                                    //////processor.Draw3dText(g,
                                    //////                   Barcode,
                                    //////                     rc,
                                    //////                     SpecialEffectsTextStyle.Normal,
                                    //////                     SpecialEffectsTextAlignmentFlags.HorizontalCenter | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                    //////                     0, /* horizontal  shadow position */
                                    //////                     0, /* vertical shadow position */
                                    //////                     Color.Black, /* text color, blue */
                                    //////                     backColorBarcode,/* shadow color, black */
                                    //////                     backColorBarcode, /* border color, white */
                                    //////                     SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o9,
                                    //////                     null);
                                    ////StringFormat barFormat = new StringFormat();
                                    ////barFormat.Alignment = StringAlignment.Center;

                                    //////barFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap | StringFormatFlags.DirectionRightToLeft;
                                    ////barFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;

                                    ////barFormat.LineAlignment = StringAlignment.Center;
                                    //////Rectangle rcBarcode = new Rectangle(rc.X, rc.Y, Convert.ToInt16(rc.Width / gFont.DpiX * board.BoardBaseInfo.DPI), Convert.ToInt16(rc.Height / gFont.DpiX * board.BoardBaseInfo.DPI));
                                    ////g.DrawString(Barcode, DateTransfer.SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o92, new SolidBrush(Color.Black), rc, barFormat);
                                    //////g.DrawString("123", textFont, new SolidBrush(Color.Black), rc,barFormat);

                                    ////recX += BARCODEWIDTH;

                                    //打条码
                                    Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                    //g.DrawString (Brushes

                                    //processor.Draw3dShape(g, SpecialEffectsShape.Rectangle, rc, Color.White, null, rc, SpecialEffectsBackStyle.Opaque, Color.White, SpecialEffectsFillStyle.Solid, Color.White, SpecialEffectsBorderStyle.Solid, 0, Color.White, Color.White, SpecialEffectsInnerStyle.None, 0, Color.White, Color.White, SpecialEffectsOuterStyle.None, 0, 0, 0, Color.White, null);

                                    processor.Draw3dText(g,
                                                        Barcode,
                                                        rc,
                                                        SpecialEffectsTextStyle.Normal,
                                                        SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                        0, /* horizontal  shadow position */
                                                        0, /* vertical shadow position */
                                                        Color.Black,/* text color, blue */
                                                        Color.White,/* shadow color, black */
                                                        Color.White, /* border color, white */
                                                        textBarFont3o92,
                                                        null);



                                    //StringFormat barFormat = new StringFormat();
                                    //barFormat.Alignment = StringAlignment.Center;
                                    //barFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;
                                    //barFormat.LineAlignment = StringAlignment.Center;
                                    ////Rectangle rcBarcode = new Rectangle(rc.X, rc.Y, Convert.ToInt16(rc.Width / gFont.DpiX * board.BoardBaseInfo.DPI), Convert.ToInt16(rc.Height / gFont.DpiX * board.BoardBaseInfo.DPI));

                                    //Font barF = DateTransfer.SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o92;
                                    //g.DrawString(Barcode, barF, new SolidBrush(Color.Black), rc, barFormat);
                                    //g.DrawString("123", textFont, new SolidBrush(Color.Black), rc,barFormat);

                                    recX += BARCODEWIDTH;

                                }
                                else
                                {

                                }


                                //写其文字信息

                                recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                                string productName = "";
                                string leftProduct = "";
                                picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                                int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                                if (PIndex > 0)
                                {
                                    productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                                    leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex);
                                }
                                else
                                {
                                    productName = picInfo.BasePhotoInfo.PhotoName;
                                    leftProduct = "-";
                                }

                                //SpecialEffectsTextAlignmentFlags alignHorizontal = SpecialEffectsTextAlignmentFlags.Left;
                                //if (TextAlignType == 0)
                                //{
                                //    alignHorizontal = SpecialEffectsTextAlignmentFlags.Left;

                                //}
                                //else if (TextAlignType == 1)
                                //{
                                //    alignHorizontal = SpecialEffectsTextAlignmentFlags.Right;
                                //}
                                //else
                                //{
                                //    alignHorizontal = SpecialEffectsTextAlignmentFlags.HorizontalCenter;
                                //}
                                string text = "";
                                try
                                {
                                    text = GetBarCodeStringByCutsom(picInfo, board).Trim('\\');
                                }
                                catch
                                {

                                }
                                SizeF sizetextF = gFont.MeasureString(text, textFont);

                                StringFormat textFormat = new StringFormat();
                                textFormat.Alignment = StringAlignment.Near;
                                textFormat.LineAlignment = StringAlignment.Center;
                                textFormat.FormatFlags = StringFormatFlags.DisplayFormatControl;

                                //textFormat.
                                Rectangle rcFont = new Rectangle(recX, 2, barcodeImageTemp.Width - recX, BARCODEHEIDHT);

                                //processor.Draw3dText(g,
                                //                    text,
                                //                    rcFont,
                                //                    SpecialEffectsTextStyle.Normal,
                                //                    alignHorizontal | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                //                    0, /* horizontal  shadow position */
                                //                    0, /* vertical shadow position */
                                //                    FontColor,/* text color, blue */
                                //                    backColorBarcode,/* shadow color, black */
                                //                    backColorBarcode, /* border color, white */
                                //                    textFont,
                                //                    null);
                                gFont.PageUnit = GraphicsUnit.Pixel;

                                string newText = text;
                                if (DateTransfer.TextAlignType == 0)//左
                                {
                                    newText = text;
                                }
                                else if (DateTransfer.TextAlignType == 1)//右对齐
                                {
                                    for (int m = 0; m < text.Length; m++)
                                    {
                                        newText = text.Substring(m);

                                        SizeF sizenewtextF = gFont.MeasureString(newText, textFont, barcodeImageTemp.Width - recX, textFormat);

                                        if (sizenewtextF.Width <= (barcodeImageTemp.Width - recX) * gFont.DpiX / board.BoardBaseInfo.DPI)
                                        {
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    newText = text;
                                    textFormat.Alignment = StringAlignment.Center;
                                    textFormat.LineAlignment = StringAlignment.Center;
                                }


                                g.PageUnit = GraphicsUnit.Pixel;
                                g.DrawString(newText, textFont, new SolidBrush(FontColor), rcFont, textFormat);




                                g.Dispose();
                                //gFont.Dispose();
                                ColorImgBlock.Dispose();//释放色块的资源
                                #endregion

                                UPTLab("正在粘贴图片");

                                #region 向中间图片mdiImageTemp图贴图片

                                CombineFastCommand cfcCommand = new CombineFastCommand();
                                Rectangle barCodeRec, picRec;

                                //if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左
                                //{
                                //    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                //    rcBarcode.Angle = 270 * 100;
                                //    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                //    rcBarcode.Flags = RotateCommandFlags.Resize;
                                //    rcBarcode.Run(barcodeImageTemp);


                                //    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                //    barCodeRec = new Rectangle(smallPicImage.Width - BARCODEHEIDHT, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                                //}
                                //else  //0:条码放在下面
                                //{
                                barCodeRec = new Rectangle(0, smallPicImage.Height - BARCODEHEIDHT, barcodeImageTemp.Width, BARCODEHEIDHT);
                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);

                                //}

                                CombineFastCommand cfcBarcode = new CombineFastCommand();
                                cfcBarcode.SourcePoint = Point.Empty;
                                cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                                cfcBarcode.DestinationImage = midImageTmp;


                                //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                                //{
                                //    UPTLab("对条码进行锐化");
                                //    SharpenCommand command = new SharpenCommand();
                                //    command.Sharpness = 950;
                                //    command.Run(barcodeImageTemp);
                                //}

                                //UPTLab("贴条码");
                                //贴条码
                                cfcBarcode.DestinationRectangle = barCodeRec;
                                cfcBarcode.Run(barcodeImageTemp);

                                //UPTLab("贴图片");
                                //贴图片
                                cfcBarcode.DestinationRectangle = picRec;
                                cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                                cfcBarcode.Run(smallPicImage);

                                barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                                #endregion
                            }
                            else
                            {
                                //向中间图片上贴图片
                                CombineFastCommand cfcCommand = new CombineFastCommand();
                                cfcCommand.DestinationRectangle = new Rectangle(
                                                                                   0,
                                                                                   0,
                                                                                   smallPicImage.Width,
                                                                                   smallPicImage.Height);
                                cfcCommand.SourcePoint = Point.Empty;
                                cfcCommand.DestinationImage = midImageTmp;
                                cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                                cfcCommand.Run(smallPicImage);
                            }
                        }
                        #endregion

                        UPTLab("正在绘制中间图边框");
                        #region //给中间图画边框
                        if (DateTransfer.IsPrintLine)
                        {
                            Graphics g2 = null;
                            try
                            {
                                //SpecialEffectsProcessor processor2 = new SpecialEffectsProcessor();
                                //g2 = midImageTmp.CreateGdiPlusGraphics().Graphics;

                                //Rectangle rcShape2 = new Rectangle(0, 0, midImageTmp.ImageWidth, midImageTmp.ImageHeight);


                                //processor2.Draw3dShape(g2,
                                //                         SpecialEffectsShape.Rectangle, /* star shape */
                                //                         rcShape2,  /* destination rectangle */
                                //                         Color.Black, /* background color, blue */
                                //                         null, /* use this to place an image in the background */
                                //                         rcShape2, /* display background rectangle */
                                //                         SpecialEffectsBackStyle.TranslucentTiledImage, /* style flags for 3D shape */
                                //                         Color.Black, /* foreground color, red */
                                //                         SpecialEffectsFillStyle.Transparent, /* foreground style */
                                //                         Color.Black, /* border color, red */
                                //                         SpecialEffectsBorderStyle.Solid, /* border style */
                                //                         BoardLineWidth, /* border width */
                                //                         Color.Black, /* inner band highlight color, white */
                                //                         Color.Black, /* inner band shadow color */
                                //                         SpecialEffectsInnerStyle.None, /* inner band style */
                                //                         0, /* inner band width */
                                //                         Color.Black, /* outer band highlight color, RED */
                                //                         Color.Black, /* outer band shadow color */
                                //                         SpecialEffectsOuterStyle.None,/* outer band style */
                                //                         0, /* outer band width */
                                //                         0, /* horizontal shadow position */
                                //                         0, /* vertical shadow position */
                                //                         Color.Black, /* shadow color, black */
                                //                         null);    /* no region handle */
                                DrowBordLine(ref midImageTmp);
                            }
                            catch (Exception Boardex)//如果添加边框出错就不添加
                            {
                                WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.BasePhotoInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                                DrowBordLine(ref midImageTmp);
                            }
                            finally
                            {
                                if (g2 != null)
                                {
                                    g2.Dispose();
                                }
                            }
                        }
                        #endregion
                        UPTLab("正在粘贴图片:ID" + picInfo.BasePhotoInfo.PhotoId + ",照片" + picInfo.BasePhotoInfo.PicPath);
                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }



                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                                                                        pointX,//在大图上的坐标
                                                                        pointY,
                                                                        midImageTmp.Width,//长和宽
                                                                        midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (board.IsTransverse)//自动裁切模式IsTransverse 改为是否使用裁切选择项目
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();

                            photoP.X = pointX;
                            photoP.Y = pointY;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;

                            if (!picInfo.IsWhirl)
                            {
                                photoP.Angle = 0;
                            }
                            else
                            {
                                photoP.Angle = 90;
                            }
                            //计算DXF宽高
                            //SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.DxfContent);
                            //DxfObjecctInfo mindxfObjecctInfo =
                            //    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                            //DxfObjecctInfo maxdxfObjecctInfo =
                            //  SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                            //DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                            //DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                            //photoP.DXFWidth = maxPointer.X - minPointer.X;
                            //photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                            //photoP.DXFContent = picInfo.DxfContent;

                            if (!string.IsNullOrEmpty(picInfo.BasePhotoInfo.DXFFilePath))
                            {
                                SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.BasePhotoInfo.DXFContent);
                                DxfObjecctInfo mindxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                                DxfObjecctInfo maxdxfObjecctInfo =
                                    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                                DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                                DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                                photoP.DXFWidth = maxPointer.X - minPointer.X;
                                photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                                photoP.DXFContent = picInfo.DxfContent;
                            }
                            else
                            {
                                photoP.DXFWidth = 0;
                                photoP.DXFHeigth = 0;
                                photoP.DXFContent = null;
                            }
                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.PhotoS.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.BasePhotoInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.BasePhotoInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;

                int qipanHeight = Convert.ToInt32(0.5 / 2.54 * board.BoardBaseInfo.DPI);

                if (DateTransfer.CutMinPhotoNum == 0)
                {
                    //不处理
                }
                else
                {
                    if (board.PhotoS.Count <= DateTransfer.CutMinPhotoNum)
                    {
                        DateTransfer.IsAutoCut = false;
                    }
                    else
                    {
                        //不处理
                    }
                }
                if (DateTransfer.IsAutoCut)//自动裁切模式要替换最终destImage
                {
                    UPTLab("创建自动裁切信息");
                    ///创建大板的条码信息
                    //RasterImage destTempImage = destImage;//先将名称替换掉

                    string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)BoardPixHeight / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                    qipanHeight = smallTop.Height;
                    RasterImage boardPointInfoImage = new RasterImage(
                                                        RasterMemoryFlags.Conventional,
                                                        destImage.Height,
                                                        qipanHeight,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//条码信息色块中间白板图

                    RasterImage destTempImage = new RasterImage(RasterMemoryFlags.Conventional,
                                                        destImage.Width + qipanHeight,
                                                        destImage.Height,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//);
                    ///填充颜色
                    FillCommand fcommandW = new FillCommand();
                    fcommandW.Color = new RasterColor(255, 255, 255);
                    fcommandW.Run(destTempImage);
                    fcommandW.Run(boardPointInfoImage);
                    destTempImage.XResolution = destImage.XResolution;

                    destTempImage.YResolution = destImage.YResolution;
                    //条码文字信息
                    //Graphics g = barcodeImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                    //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    int recCurrX = XExcursion, recCurrY = 0;





                    if (File.Exists(Application.StartupPath + "\\temBar.bmp"))
                    {
                        File.Delete(Application.StartupPath + "\\temBar.bmp");
                    }


                    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                    rcBarcode.Angle = 270 * 100;
                    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                    rcBarcode.Flags = RotateCommandFlags.Resize;
                    rcBarcode.Run(smallTop);

                    CombineFastCommand cfctop = new CombineFastCommand();
                    cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                    cfctop.SourcePoint = Point.Empty;
                    cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(smallTop);
                    cfctop.DestinationRectangle = new Rectangle(smallTop.Width, 0, destImage.Width, destImage.Height);
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(destImage);
                    destImage = destTempImage;//重新赋值

                    //写入文件 
                    StringBuilder sbWriter = new StringBuilder();
                    //sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.DPI);
                    sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.PrinterName.Trim());
                    foreach (PhotoPoint pp in listPhotoInfoForCut)
                    {
                        string mmy = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                        string mmX = (((double)(board.BoardBaseInfo.Height - pp.Y - pp.Height) / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                        string mmWidth = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                        string mmheight = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                        string dxfFlag = "DXF";
                        string strWriter = "";
                        if (pp.DXFContent == null)
                        {
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                        }
                        else
                        {
                            string angleStr = pp.Angle.ToString();
                            string wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                            string hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                            string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", ";");
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                        hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                        }
                        sbWriter.AppendLine(strWriter);

                    }
                    string FileName = _curCutFileFullPath;
                    if (File.Exists(FileName))
                    {
                        File.Delete(FileName);
                    }
                    WrtieTextEn(sbWriter, FileName);
                    EncryptionAndSave(board.BoardBaseInfo.BoardId, sbWriter);
                }
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;

                if (board.AddSharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    SharpenCommand command = new SharpenCommand();
                    command.Sharpness = board.AddSharpen;
                    command.Run(destImage);
                }

                UPTLab("正在保存大图...");
                bool isNeedAddIcc = false;
                if (!string.IsNullOrEmpty(board.IccPath))
                {
                    if (board.IccPath.EndsWith(".icc") || board.IccPath.EndsWith(".icm"))
                    {
                        if (File.Exists(board.IccPath))
                        {
                            isNeedAddIcc = true;//只有当ICCPATH不为空字符串，则是以。ICC、ICM结尾的，且文件存在的才加ICC
                        }
                    }

                }
                if (DateTransfer.AddIccByType == 0)
                {
                    isNeedAddIcc = false;
                }
                if (isNeedAddIcc)//需要加载ICC
                {
                    if (DateTransfer.AddIccByType == 1)//需要用PS加载ICC
                    {
                        //先保存到本地,等加载好ICC时存到网络路径                  
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }

                        //再调用PS加载ICC
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                            }
                            catch { }
                            string strPicFormat = "JPEG";
                            //string strInputIcc = "ColorMatch RGB";
                            string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            if (board.IsTransverse)//竖向的就转90
                                intRatate = -90;
                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);


                            string strResult = psApp.AddICC(iccName, strTempPath, destFileName);


                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件错误" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                            }
                            catch { }
                        }
                    }
                    else if (DateTransfer.AddIccByType == 2)
                    {
                        //调用IccProcessEXE 加载ICC

                        string tamPath = Environment.GetEnvironmentVariable("TEMP");
                        strTempPath = tamPath + "\\abc.jpg";
                        string iccPath = tamPath + board.IccPath.Substring(board.IccPath.LastIndexOf("\\"));
                        string loadediccPath = tamPath + "\\def.jpg";
                        string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        string fromTempICC = tamPath + "\\sRGB Color Space Profile.icm";
                        string exePath = Application.StartupPath + "\\IccProcessEXE.exe";
                        if (File.Exists(strTempPath))
                        {
                            File.Delete(strTempPath);
                        }
                        if (File.Exists(loadediccPath))
                        {
                            File.Delete(loadediccPath);
                        }
                        if (!File.Exists(iccPath))
                        {
                            File.Copy(board.IccPath, iccPath);
                        }
                        if (!File.Exists(fromTempICC))
                        {
                            File.Copy(FromIcc, fromTempICC);
                        }
                        switch (PicFormat)
                        {

                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);

                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }
                        string iccFile = "";
                        //string FromIcc = Application.StartupPath + "\\" + "sRGB Color Space Profile.icm";
                        try
                        {
                            UPTLab("正在加载ICC:" + board.IccPath);

                            using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                            {
                                pExecuteEXE.StartInfo.FileName = exePath;
                                //pExecuteEXE.StartInfo.Arguments = @"c:\1410.jpg,c:\sRGB Color Space Profile.icm,c:\efg1.jpg,c:\dnp100305-003.icm,95";
                                // pExecuteEXE.StartInfo.Arguments = strTempPath + "," + fromTempICC + "," + loadediccPath + "," + iccPath + "," + 95;
                                pExecuteEXE.StartInfo.Arguments = strTempPath + "," + doubleQM + fromTempICC + doubleQM + "," + loadediccPath + "," + doubleQM + iccPath + doubleQM + "," + 95;
                                pExecuteEXE.Start();
                                pExecuteEXE.WaitForExit();
                            }

                            //iccFile = iccLoad.IccProcess(strTempPath, fromTempICC, loadediccPath, iccPath,"100");
                            //if (!loadediccPath.Equals(iccFile))
                            //{
                            //    UPTLab("加载ICC文件错误:");
                            //    throw new Exception("加载ICC文件错误");

                            //}
                            //else
                            //{
                            //    File.Copy(loadediccPath, destFileName);
                            //}
                            if (File.Exists(loadediccPath))
                            {
                                try
                                {
                                    File.Copy(loadediccPath, destFileName, true);
                                }
                                catch (Exception ex)
                                {
                                    UPTLab("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有路径访问权限");
                                    throw new Exception("文件拷贝到'" + destFileName + "'时出错，请查看生成图片机器是否有改路径访问权限");

                                }
                            }
                        }
                        catch
                        {
                        }

                    }
                    else if (DateTransfer.AddIccByType == 3)
                    {
                        //LEADTOOLS加载ICC


                        try
                        {

                            //IccProfileExtended iccProfile = new IccProfileExtended();

                            //// load the ICC from an image, by specifying the image's name, and the 1-based page number that contains the ICC. 
                            //// to load the ICC from an Image that is in a stream, put the stream instead of the file name. 
                            //iccProfile.ReadFromImage(@"E:\开单目录\back-wall-ms  山富灯片ok曲线\25.5x17.4x25.tif", 1);

                            //// at this point, the iccProfile object contains the ICC profile that was found in the image, 
                            //// you can use it as you want, but for this example, we will save it in a seperate ICC profile file. 
                            //// generate the profileId. For the time being, it will be filled with 0's 
                            //iccProfile.GenerateProfileId();

                            //// finally generate the new Icc Profile by updating the Data Array 
                            //// and then generating the file 
                            //iccProfile.UpdateDataArray();
                            switch (PicFormat)
                            {
                                case 0: codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Jpeg, 24);
                                    break;
                                case 1:
                                    codecs.Save(destImage, board.BoardBaseInfo.PicPath, RasterImageFormat.Tif, 24);
                                    break;
                            }
                            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                            //IccProfileExtended iccP=new IccProfileExtended((
                            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                        }
                        catch (Exception ef)
                        {

                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }



                    }
                    else
                    {



                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                                break;
                        }


                    }
                }
                else//不需要加载ICC，则直接保存
                {


                    switch (PicFormat)
                    {
                        case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }
                }

                #region //写入ICC文件


                #endregion


                destImage.Dispose();


                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                board.BoardBaseInfo.PicPath = destFileName;
                _mainBLL.MakeBigPicSusscess(board);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString());


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                int boardstatus = _mainBLL.SetBoardStatus2(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                if (boardstatus == 0)
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":无法修改Board状态，如有必要手动删除版" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                else
                {
                    WriteLogForCheck.WriteLogFile(DateTime.Now + ":" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                }
                UPTLabBoardErrorList();
            }
            finally
            {
                errText = "";
            }
        }
        void FillWhite(ref RasterImage destImage)
        {
            FillCommand fcommand = new FillCommand();
            fcommand.Color = new RasterColor(0, 0, 0);


            fcommand.Run(destImage);
        }
        private void MakeBigPicH2Cmyk(BoardInfo_MakeBigPic board)
        {
            int XExcursion = 0;//X坐标偏移量
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            //int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            //int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            int boardPixWidth = board.BoardBaseInfo.Height; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.Length;//大图的高,相素高宽互换

            //XExcursion = boardPixWidth;
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸

            destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            int pixLineWidth = 0;
            if (DateTransfer.IsPrintLine)
            {
                pixLineWidth = 1;
            }

            DateTransfer.IsAutoCut = board.IsTransverse;

            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {

                RasterCodecs codecs = new RasterCodecs();
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    boardPixWidth,//+1保证最右边的框线可以出来
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);
                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;
                Color backColor = DateTransfer.BackColor;

                FillCommand fcommand = new FillCommand();
                //fcommand.Color = new RasterColor(128, 128, 128);
                fcommand.Color = new RasterColor(backColor);

                fcommand.Run(destImage);
                string PATH = Application.StartupPath + "\\tiffTemp.tif";
                if (File.Exists(PATH))
                {
                    File.Delete(PATH);

                }
                codecs.Save(destImage, PATH, RasterImageFormat.TifCmyk, 24);

                destImage = codecs.LoadCmykPlanes(PATH, 8, 1);

                UPTLab("渲染大图框架成功");
                foreach (var picInfo in board.PhotoS)
                {
                    UPTLab("正在添加小图:" + picInfo.BasePhotoInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上
                        // 根据加急级别以及是否清空等确定字体的颜色

                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        if (!string.IsNullOrEmpty(DateTransfer.RemarkKeysColor))
                        {
                            FontColor = GetRemarkColor(picInfo.BasePhotoInfo.PicPath);

                        }
                        RasterImage smallPicImage = CreatePicImg2Cmyk(picInfo, codecs, board);//
                        UPTLab("正在合成中间图");
                        RasterImage midImageTmp = CreateMidImgV(picInfo);//带有条码的中间图是竖版中间图
                        //FillWhite(ref midImageTmp);
                        string midPATH = Application.StartupPath + "\\midPath.tiff";
                        codecs.Save(midImageTmp, midPATH, RasterImageFormat.TifCmyk, 24);
                        midImageTmp = codecs.LoadCmykPlanes(midPATH, 8, 1);

                        //UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)

                        //是否有条码
                        if (picInfo.barCodeStatus != SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode)//有条码
                        {
                            #region//条码信息先不加
                            ///*
                            //RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board);//条码图片的临时图片

                            ////RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块
                            //RasterImage ColorImgBlock = GetColorBlock2(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                            //UPTLab("粘贴色块");
                            //CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            //cfcBarcode1.DestinationRectangle = new Rectangle(
                            // 0,
                            // 0,
                            // barcodeImageTemp.Width,
                            // barcodeImageTemp.Height);

                            //cfcBarcode1.SourcePoint = Point.Empty;
                            //cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            //cfcBarcode1.DestinationImage = barcodeImageTemp;
                            //cfcBarcode1.Run(ColorImgBlock);


                            //UPTLab("生成条码及文字");

                            //#region 打印条码及文字信息
                            //Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            //int recX = ColorImgBlock.Width + 5, recY = -2;
                            //string Barcode = "";
                            //string nullBar = " ";
                            //SizeF sizeF;
                            //if (SelectBarCodeType == 1)
                            //{
                            //    recX += 20;
                            //    //Barcode = cifi.EAN13(picInfo.BasePhotoInfo.PhotoId.ToString());
                            //    //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                            //    Barcode = "*" + picInfo.BasePhotoInfo.PhotoId + "*";
                            //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                            //    nullBar = picInfo.BasePhotoInfo.PhotoId.ToString();
                            //}
                            //else if (SelectBarCodeType == 0)
                            //{
                            //    recX += 20;
                            //    int startIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('-');
                            //    int endIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('.');
                            //    Barcode = "*" + picInfo.BasePhotoInfo.PhotoName.Substring(startIndex + 1, endIndex - startIndex - 1) + "*";
                            //    sizeF = gFont.MeasureString(Barcode, textBarFont3o9);

                            //}
                            //else
                            //{
                            //    Barcode = "";
                            //    sizeF = gFont.MeasureString(Barcode, textBarFont3o92);
                            //}

                            //BARCODEWIDTH = ((int)sizeF.Width) + 1;//条码的宽度

                            ////色块就有50
                            ////if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            //if (MinPhotoRemarkLength * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                            //{
                            //    ////打条码
                            //    //Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                            //    //processor.Draw3dText(g,
                            //    //                   Barcode,
                            //    //                     rc,
                            //    //                     SpecialEffectsTextStyle.Normal,
                            //    //                     SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                            //    //                     0, /* horizontal  shadow position */
                            //    //                     0, /* vertical shadow position */
                            //    //                     Color.Black, /* text color, blue */
                            //    //                     Color.White,/* shadow color, black */
                            //    //                     Color.White, /* border color, white */
                            //    //                     SelectBarCodeType == 1 ? textBarFont3o92 : textBarFont3o9,
                            //    //                     null);

                            //    //recX += BARCODEWIDTH;
                            //}
                            //else
                            //{

                            //}


                            ////写其文字信息

                            //recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            //string productName = "";
                            //string leftProduct = "";
                            //picInfo.BasePhotoInfo.PhotoName = picInfo.BasePhotoInfo.PhotoName.TrimStart('\\');
                            //int PIndex = picInfo.BasePhotoInfo.PhotoName.IndexOf('\\');
                            //if (PIndex > 0)
                            //{
                            //    productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                            //    leftProduct = picInfo.BasePhotoInfo.PhotoName.Substring(PIndex);
                            //}
                            //else
                            //{
                            //    productName = picInfo.BasePhotoInfo.PhotoName;
                            //    leftProduct = "-";
                            //}

                            //SpecialEffectsTextAlignmentFlags alignHorizontal = SpecialEffectsTextAlignmentFlags.Left;
                            //if (TextAlignType == 0)
                            //{
                            //    alignHorizontal = SpecialEffectsTextAlignmentFlags.Left;

                            //}
                            //else if (TextAlignType == 1)
                            //{
                            //    alignHorizontal = SpecialEffectsTextAlignmentFlags.Right;
                            //}
                            //else
                            //{
                            //    alignHorizontal = SpecialEffectsTextAlignmentFlags.HorizontalCenter;
                            //}

                            //Rectangle rcFont = new Rectangle(recX - 20, -3, barcodeImageTemp.Width - recX, BARCODEHEIDHT);
                            //string text = "";
                            //try
                            //{
                            //    text = GetBarCodeStringByCutsom(picInfo, board);
                            //}
                            //catch
                            //{

                            //}
                            ////processor.Draw3dText(g,
                            ////                    text,
                            ////                    rcFont,
                            ////                    SpecialEffectsTextStyle.Normal,
                            ////                    alignHorizontal | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                            ////                    0, /* horizontal  shadow position */
                            ////                    0, /* vertical shadow position */
                            ////                    FontColor,/* text color, blue */
                            ////                    Color.White,/* shadow color, black */
                            ////                    Color.White, /* border color, white */
                            ////                    textFont,
                            ////                    null);

                            //g.Dispose();
                            //ColorImgBlock.Dispose();//释放色块的资源
                            //#endregion

                            //UPTLab("正在粘贴图片");

                            //#region 向中间图片mdiImageTemp图贴图片

                            //CombineFastCommand cfcCommand = new CombineFastCommand();
                            //Rectangle barCodeRec, picRec;

                            //if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左\右边 实际 出来是上下
                            //{
                            //    //RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //    //rcBarcode.Angle = 270 * 100;
                            //    //rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //    //rcBarcode.Flags = RotateCommandFlags.Resize;
                            //    //rcBarcode.Run(barcodeImageTemp);

                            //    //barCodeRec = new Rectangle(0, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                            //    //picRec = new Rectangle(BARCODEHEIDHT, 0, smallPicImage.Width, smallPicImage.Height);

                            //    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //    //barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                            //    barCodeRec = new Rectangle(0, smallPicImage.Height, smallPicImage.Width, BARCODEHEIDHT);
                            //}
                            //else  //0:条码放在下面
                            //{
                            //    //barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, BARCODEHEIDHT);
                            //    //picRec = new Rectangle(0, BARCODEHEIDHT, smallPicImage.Width, smallPicImage.Height);
                            //    RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                            //    rcBarcode.Angle = 270 * 100;
                            //    rcBarcode.FillColor = new RasterColor(255, 255, 255);
                            //    rcBarcode.Flags = RotateCommandFlags.Resize;
                            //    rcBarcode.Run(barcodeImageTemp);
                            //    picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                            //    barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIDHT, smallPicImage.Height);
                            //}

                            //CombineFastCommand cfcBarcode = new CombineFastCommand();
                            //cfcBarcode.SourcePoint = Point.Empty;
                            //cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            //cfcBarcode.DestinationImage = midImageTmp;


                            //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                            //{
                            //    UPTLab("对条码进行锐化");
                            //    SharpenCommand command = new SharpenCommand();
                            //    command.Sharpness = 950;
                            //    command.Run(barcodeImageTemp);
                            //}

                            ////UPTLab("贴条码");
                            ////贴条码
                            //cfcBarcode.DestinationRectangle = barCodeRec;
                            //cfcBarcode.Run(barcodeImageTemp);

                            ////UPTLab("贴图片");
                            ////贴图片
                            //cfcBarcode.DestinationRectangle = picRec;
                            //cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            //cfcBarcode.Run(smallPicImage);

                            //barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                            //#endregion
                            #endregion

                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                                                               pixLineWidth,
                                                                               pixLineWidth,
                                                                               smallPicImage.Width,
                                                                               smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            midImageTmp.Page = 1;
                            smallPicImage.Page = 1;
                            cfcCommand.Run(smallPicImage);
                            midImageTmp.Page = 2;
                            smallPicImage.Page = 2;
                            cfcCommand.Run(smallPicImage);
                            midImageTmp.Page = 3;
                            smallPicImage.Page = 3;
                            cfcCommand.Run(smallPicImage);
                            midImageTmp.Page = 4;
                            smallPicImage.Page = 4;
                            cfcCommand.Run(smallPicImage);

                        }
                        else//无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                                                               pixLineWidth,
                                                                               pixLineWidth,
                                                                               smallPicImage.Width,
                                                                               smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            midImageTmp.Page = 1;
                            smallPicImage.Page = 1;
                            cfcCommand.Run(smallPicImage);
                            midImageTmp.Page = 2;
                            smallPicImage.Page = 2;
                            cfcCommand.Run(smallPicImage);
                            midImageTmp.Page = 3;
                            smallPicImage.Page = 3;
                            cfcCommand.Run(smallPicImage);
                            midImageTmp.Page = 4;
                            smallPicImage.Page = 4;
                            cfcCommand.Run(smallPicImage);

                        }
                        #endregion

                        UPTLab("正在绘制中间图边框");
                        #region //给中间图画边框
                        if (DateTransfer.IsPrintLine)
                        {
                            Graphics g2 = null;
                            try
                            {
                                //SpecialEffectsProcessor processor2 = new SpecialEffectsProcessor();
                                //g2 = midImageTmp.CreateGdiPlusGraphics().Graphics;

                                //Rectangle rcShape2 = new Rectangle(0, 0, midImageTmp.ImageWidth, midImageTmp.ImageHeight);


                                //processor2.Draw3dShape(g2,
                                //                         SpecialEffectsShape.Rectangle, /* star shape */
                                //                         rcShape2,  /* destination rectangle */
                                //                         Color.Black, /* background color, blue */
                                //                         null, /* use this to place an image in the background */
                                //                         rcShape2, /* display background rectangle */
                                //                         SpecialEffectsBackStyle.TranslucentTiledImage, /* style flags for 3D shape */
                                //                         Color.Black, /* foreground color, red */
                                //                         SpecialEffectsFillStyle.Transparent, /* foreground style */
                                //                         Color.Black, /* border color, red */
                                //                         SpecialEffectsBorderStyle.Solid, /* border style */
                                //                         2, /* border width */
                                //                         Color.Black, /* inner band highlight color, white */
                                //                         Color.Black, /* inner band shadow color */
                                //                         SpecialEffectsInnerStyle.None, /* inner band style */
                                //                         0, /* inner band width */
                                //                         Color.Black, /* outer band highlight color, RED */
                                //                         Color.Black, /* outer band shadow color */
                                //                         SpecialEffectsOuterStyle.None,/* outer band style */
                                //                         1, /* outer band width */
                                //                         0, /* horizontal shadow position */
                                //                         0, /* vertical shadow position */
                                //                         Color.Black, /* shadow color, black */
                                //                         null);    /* no region handle */


                                //using (RasterImageGdiPlusGraphicsContainer container = midImageTmp.CreateGdiPlusGraphics())
                                //{
                                //    using (Pen pen = new Pen(Color.Black, 2))
                                //    {
                                //        // use anti-alias lines
                                //        container.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                                //        container.Graphics.DrawLine(pen, new Point(0, 0), new Point(midImageTmp.ImageWidth, 0));
                                //        container.Graphics.DrawLine(pen, new Point(0, 0), new Point(0, midImageTmp.ImageHeight));
                                //        container.Graphics.DrawLine(pen, new Point(0, midImageTmp.ImageHeight), new Point(midImageTmp.ImageWidth, midImageTmp.ImageHeight));
                                //        container.Graphics.DrawLine(pen, new Point(midImageTmp.ImageWidth, 0), new Point(midImageTmp.ImageWidth, midImageTmp.ImageHeight));
                                //        container.Graphics.Save();
                                //        //midImageTmp.s
                                //    }
                                //}
                            }
                            catch (Exception Boardex)//如果添加边框出错就不添加
                            {
                                WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.BasePhotoInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                            }
                            finally
                            {
                                if (g2 != null)
                                {
                                    g2.Dispose();
                                }
                            }
                        }
                        #endregion
                        UPTLab("正在粘贴图片:ID" + picInfo.BasePhotoInfo.PhotoId + ",照片" + picInfo.BasePhotoInfo.PicPath);
                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }



                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                                                                        pointY,//在大图上的坐标
                                                                        pointX,
                                                                        midImageTmp.Width,//长和宽
                                                                        midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        destImage.Page = 1;
                        midImageTmp.Page = 1;
                        midCommand.Run(midImageTmp);
                        destImage.Page = 2;
                        midImageTmp.Page = 2;
                        midCommand.Run(midImageTmp);
                        destImage.Page = 3;
                        midImageTmp.Page = 3;
                        midCommand.Run(midImageTmp);
                        destImage.Page = 4;
                        midImageTmp.Page = 4;
                        midCommand.Run(midImageTmp);
                        //string File1 = @"D:\Projects\newSmallERP\SmallERP\SmallERP.Host\bin\Debug\123456.tif";

                        //codecs.SaveCmykPlanes(midImageTmp, File1, RasterImageFormat.TifCmyk, 0, 1, CodecsSavePageMode.Replace);

                        if (board.IsTransverse)//自动裁切模式IsTransverse 改为是否使用裁切选择项目
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();

                            photoP.X = pointY;
                            photoP.Y = pointX;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;
                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.PhotoS.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.BasePhotoInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.BasePhotoInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;

                int qipanHeight = Convert.ToInt32(0.5 / 2.54 * board.BoardBaseInfo.DPI);

                if (DateTransfer.CutMinPhotoNum == 0)
                {
                    //不处理
                }
                else
                {
                    if (board.PhotoS.Count <= DateTransfer.CutMinPhotoNum)
                    {
                        DateTransfer.IsAutoCut = false;
                    }
                    else
                    {
                        //不处理
                    }
                }
                if (DateTransfer.IsAutoCut)//自动裁切模式要替换最终destImage
                {
                    UPTLab("创建自动裁切信息");
                    ///创建大板的条码信息
                    //RasterImage destTempImage = destImage;//先将名称替换掉
                    RasterImage boardPointInfoImage = new RasterImage(
                                                        RasterMemoryFlags.Conventional,
                                                        destImage.Height,
                                                        qipanHeight,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//条码信息色块中间白板图
                    string PointBoard = Application.StartupPath + "\\PointBoard.tiff";

                    codecs.Save(destImage, PointBoard, RasterImageFormat.TifCmyk, 24);
                    boardPointInfoImage = codecs.LoadCmykPlanes(PointBoard, 8, 1);
                    RasterImage destTempImage = new RasterImage(RasterMemoryFlags.Conventional,
                                                        destImage.Width,
                                                        destImage.Height + qipanHeight,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//);
                    string destTempImagePath = Application.StartupPath + "\\destTempImage.tiff";

                    codecs.Save(destTempImage, destTempImagePath, RasterImageFormat.TifCmyk, 24);
                    destTempImage = codecs.LoadCmykPlanes(destTempImagePath, 8, 1);
                    ///填充颜色
                    FillCommand fcommandW = new FillCommand();
                    fcommandW.Color = new RasterColor(255, 255, 255);
                    fcommandW.Run(destTempImage);
                    fcommandW.Run(boardPointInfoImage);
                    destTempImage.XResolution = board.BoardBaseInfo.DPI;

                    destTempImage.YResolution = board.BoardBaseInfo.DPI;
                    //条码文字信息
                    //Graphics g = barcodeImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                    //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    int recCurrX = XExcursion, recCurrY = 0;


                    if (File.Exists(Application.StartupPath + "\\temBar.bmp"))
                    {
                        File.Delete(Application.StartupPath + "\\temBar.bmp");
                    }
                    string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                    RasterImage smallTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                    string smallTopPath = Application.StartupPath + "\\smallTopPath.tif";

                    codecs.Save(smallTop, smallTopPath, RasterImageFormat.TifCmyk, 24);
                    smallTop = codecs.LoadCmykPlanes(smallTopPath, 8, 1);
                    CombineFastCommand cfctop = new CombineFastCommand();
                    cfctop.DestinationRectangle = new Rectangle(0, 0, smallTop.Width, smallTop.Height);
                    cfctop.SourcePoint = Point.Empty;
                    cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                    cfctop.DestinationImage = destTempImage;
                    destTempImage.Page = 1;
                    smallTop.Page = 1;
                    cfctop.Run(smallTop);
                    destTempImage.Page = 2;
                    smallTop.Page = 2;
                    cfctop.Run(smallTop);
                    destTempImage.Page = 3;
                    smallTop.Page = 3;
                    cfctop.Run(smallTop);
                    destTempImage.Page = 4;
                    smallTop.Page = 4;
                    cfctop.Run(smallTop);
                    cfctop.DestinationRectangle = new Rectangle(0, qipanHeight, destImage.Width, destImage.Height);
                    cfctop.DestinationImage = destTempImage;
                    destTempImage.Page = 1;
                    destImage.Page = 1;
                    cfctop.Run(destImage);
                    destTempImage.Page = 2;
                    destImage.Page = 2;
                    cfctop.Run(destImage);
                    destTempImage.Page = 3;
                    destImage.Page = 3;
                    cfctop.Run(destImage);
                    destTempImage.Page = 4;
                    destImage.Page = 4;
                    cfctop.Run(destImage);

                    destImage = destTempImage;//重新赋值

                    //写入文件 
                    StringBuilder sbWriter = new StringBuilder();
                    //sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.DPI);
                    sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.PrinterName.Trim());
                    foreach (PhotoPoint pp in listPhotoInfoForCut)
                    {
                        string mmX = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                        string mmy = (((double)pp.Y / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0");
                        string mmWidth = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                        string mmheight = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMWH)).ToString("0");
                        string dxfFlag = "DXF";
                        string strWriter = "";
                        if (pp.DXFContent == null)
                        {
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                        }
                        else
                        {
                            string angleStr = pp.Angle.ToString();
                            string wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                            string hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                            string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", ";");
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                        hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                        }
                        sbWriter.AppendLine(strWriter);

                    }
                    string FileName = _curCutFileFullPath;
                    if (File.Exists(FileName))
                    {
                        File.Delete(FileName);
                    }
                    WrtieTextEn(sbWriter, FileName);
                    EncryptionAndSave(board.BoardBaseInfo.BoardId, sbWriter);
                }
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                //destImage.XResolution = board.BoardBaseInfo.DPI;
                //destImage.YResolution = board.BoardBaseInfo.DPI;

                if (board.AddSharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    SharpenCommand command = new SharpenCommand();
                    command.Sharpness = board.AddSharpen;
                    command.Run(destImage);
                }

                UPTLab("正在保存大图...");
                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;
                codecs.SaveCmykPlanes(destImage, destFileName, RasterImageFormat.TifCmyk, 0, 1, CodecsSavePageMode.Replace);
                string ICCpATH = Application.StartupPath + "\\JapanColor2001Coated.icc";
                IccProfileExtended iccProfile = new IccProfileExtended(ICCpATH);

                iccProfile.WriteToImage(destFileName, 1);

                destImage.Dispose();


                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                board.BoardBaseInfo.PicPath = destFileName;
                _mainBLL.MakeBigPicSusscess(board);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");

                ProductPicCount++;
                UplblCount(ProductPicCount.ToString());


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, ex1.Message + "," + errText);
                WriteLogForCheck.WriteLogFile(DateTime.Now + ":" + board.BoardBaseInfo.BoardId + ex1.Message + errText);
                UPTLabBoardErrorList();
            }
            finally
            {
                errText = "";
            }
        }
        private string GetBarCodeStringByCutsom(PhotoInfo_MakeBigPic picInfo, BoardInfo_MakeBigPic board)
        {
            /*
              picInfo.GridName + @"\P" +//格子号
                                                 picInfo.PhotoId + @"\O" +//照片号
                                                 picInfo.OrderProductId + @"\" +//产品号
                                                 picInfo.Remark + "\\" +
                                //picInfo.CtmName + @"\" +//客人名
                                //picInfo.PhotoName.Substring(picInfo.PhotoName.IndexOf("_") + 1).Substring(4) + @"\" +//照片名                                                
                                                 picInfo.OrderProductName + @"\" +
                                                 picInfo.ShopName + @"\B" +
                                                 board.BoardBaseInfo.BoardId + @"\" +
                                                 picInfo.Width.ToString("0.00") + "*" +
                                                 picInfo.Height.ToString("0.00") + "(" +
                                                 (picInfo.Width * 2.54).ToString("0.00") + "*" +
                                                 (picInfo.Height * 2.54).ToString("0.00") + @")\" +
                                                 DateTime.Now.ToString(),
             */

            List<BarSerInfo> barList = FrmBaseInfo.GetInitil();
            StringBuilder sbR = new StringBuilder();

            foreach (var barSet in barList)
            {
                if (!barSet.IsPrint)
                {
                    continue;
                }
                switch (barSet.Code)
                {
                    case "F1": sbR.Append(@"\" + picInfo.BasePhotoInfo.GranddadFolder); //
                        break;
                    case "F2": sbR.Append(@"\" + picInfo.BasePhotoInfo.FatherFolder);//
                        break;
                    case "PN": sbR.Append(@"\" + picInfo.OrderProductName);//
                        break;
                    case "PNAME":
                        int index = picInfo.BasePhotoInfo.PhotoName.LastIndexOf("\\");
                        if (index > 0)
                        {
                            sbR.Append(@"\" + picInfo.BasePhotoInfo.PhotoName.Substring(index));
                        }
                        else
                        {
                            sbR.Append(@"\" + picInfo.BasePhotoInfo.PhotoName);
                        }

                        break;
                    case "PREMARK": sbR.Append(@"\" + picInfo.BasePhotoInfo.PicPath);//
                        break;
                    case "PPN":
                        int PIndex = picInfo.BasePhotoInfo.PhotoName.LastIndexOf('\\');

                        string productName = "";
                        if (PIndex > 0)
                        {
                            productName = picInfo.BasePhotoInfo.PhotoName.Substring(0, PIndex);
                            //int nIndex = productName.LastIndexOf('\\');
                            //if (nIndex > 0)
                            //{
                            //    productName = productName.Substring(nIndex+1);
                            //}

                        }
                        else
                        {
                            productName = "";

                        }
                        sbR.Append(@"\" + productName);//商户名称
                        break;
                    case "PNUM": sbR.Append(@"\Z" + picInfo.BasePhotoInfo.PhotoId);//
                        break;
                    case "ONUM": sbR.Append(@"\D" + picInfo.BasePhotoInfo.OrderProductId);//产品号
                        break;

                    case "PHOTOORDER": sbR.Append(@"(" + picInfo.OrderInOrderproduct + "/" + picInfo.BasePhotoInfo.OrderNumInProduct + ")");//照片文件包照片数
                        break;
                    case "PSIZE":
                        if (DateTransfer.PhotosizeUnit == 0)
                        {
                            sbR.Append(@"\" +
                               picInfo.BasePhotoInfo.Height.ToString("0.00") + "*" +
                               picInfo.BasePhotoInfo.Width.ToString("0.00"));//照片尺寸信息
                        }
                        else if (DateTransfer.PhotosizeUnit == 1)
                        {
                            sbR.Append(@"\" +
                                //+ picInfo.BasePhotoInfo.Width.ToString("0.00") + "*" +
                                //picInfo.BasePhotoInfo.Width.ToString("0.00") + "(" +
                                                "(" + (picInfo.BasePhotoInfo.Height * 2.54).ToString("0.00") + "x" +
                                                (picInfo.BasePhotoInfo.Width * 2.54).ToString("0.00") + ")");//照片尺寸信息
                        }
                        else
                        {
                            sbR.Append(@"\" +
                                picInfo.BasePhotoInfo.Height.ToString("0.00") + "*" +
                                picInfo.BasePhotoInfo.Width.ToString("0.00") + "(" +
                                                 "(" + (picInfo.BasePhotoInfo.Height * 2.54).ToString("0.00") + "x" +
                                                 (picInfo.BasePhotoInfo.Width * 2.54).ToString("0.00") + ")");//照片尺寸信息
                        }
                        break;
                    case "DATE": sbR.Append(@"\" + DateTime.Now.ToString());//生成时间
                        break;
                    case "BID": sbR.Append(@"\B" + board.BoardBaseInfo.BoardId);
                        break;
                    default: //空
                        break;
                }
            }

            return sbR.ToString();
        }
        private void MakeBigPic(BoardInfo_MakeBigPic board)
        {
            int XExcursion = 0;
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸
            if (PicFormat == 1)
            {
                destFileName = destFileName.Substring(0, destFileName.Length - 3) + "tif";
            }
            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    boardPixWidth + 1,//+1保证最右边的框线可以出来
                    BoardPixHeight,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                FillCommand fcommand = new FillCommand();
                fcommand.Color = new RasterColor(255, 255, 255);
                fcommand.Run(destImage);

                UPTLab("生大大图框架成功");
                foreach (var picInfo in board.PhotoS)
                {
                    UPTLab("正在添加小图:" + picInfo.BasePhotoInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上
                        // 根据加急级别以及是否清空等确定字体的颜色

                        Color FontColor = GetFontColorByPhotoInfo(picInfo);
                        if (!string.IsNullOrEmpty(DateTransfer.RemarkKeysColor))
                        {
                            FontColor = GetRemarkColor(picInfo.BasePhotoInfo.PicPath);

                        }
                        RasterImage smallPicImage = CreatePicImg(picInfo, codecs, board);//小图片
                        RasterImage midImageTmp = CreateMidImg(picInfo);//带有条码的中间图
                        UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)

                        //是否有条码
                        if (picInfo.barCodeStatus != SmallERP.COM.Status.PhotoBarCodeStatus.NoBarCode)//有条码
                        {
                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board);//条码图片的临时图片

                            RasterImage ColorImgBlock = GetColorBlock(picInfo.BasePhotoInfo.OrderProductId);//色块,根据产品得到不同的色块


                            UPTLab("粘贴色块");
                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                             0,
                             0,
                             barcodeImageTemp.Width,
                             barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);


                            UPTLab("生成条码及文字");

                            #region 打印条码及文字信息
                            Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            int recX = ColorImgBlock.Width + 10, recY = 0;

                            SizeF sizeF = gFont.MeasureString("*" + picInfo.BasePhotoInfo.PhotoId.ToString() + "*", textBarFont3o9);
                            BARCODEWIDTH = ((int)sizeF.Width);//条码的宽度

                            //色块就有50
                            if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);

                                processor.Draw3dText(g,
                                                   "*" + picInfo.BasePhotoInfo.PhotoId + "*",
                                                     rc,
                                                     SpecialEffectsTextStyle.Normal,
                                                     SpecialEffectsTextAlignmentFlags.HorizontalCenter | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                     0, /* horizontal  shadow position */
                                                     0, /* vertical shadow position */
                                                     Color.Black, /* text color, blue */
                                                     Color.White,/* shadow color, black */
                                                     Color.White, /* border color, white */
                                                     textBarFont3o9,
                                                     null);

                                recX += BARCODEWIDTH;
                            }


                            //写其文字信息

                            recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            Rectangle rcFont = new Rectangle(recX, -5, barcodeImageTemp.Width - recX, BARCODEHEIDHT);
                            processor.Draw3dText(g,
                                //picInfo.GridName + @"\P" +
                                //picInfo.BasePhotoInfo.PhotoId + @"\B" +
                                //board.BoardBaseInfo.BoardId + @"\O" +
                                //picInfo.BasePhotoInfo.OrderProductId + @"\" +
                                                 picInfo.BasePhotoInfo.PhotoName + @"\" +
                                                 picInfo.OrderProductName + @"\" +
                                                 picInfo.GridName + @"\P" +
                                                 picInfo.BasePhotoInfo.PhotoId + @"\B" +
                                                 board.BoardBaseInfo.BoardId + @"\O" +
                                                 picInfo.BasePhotoInfo.OrderProductId + @"\" +
                                                 picInfo.BasePhotoInfo.Width.ToString("0.00") + "*" +
                                                 picInfo.BasePhotoInfo.Height.ToString("0.00") + "(" +
                                                 (picInfo.BasePhotoInfo.Width * 2.54).ToString("0.00") + "*" +
                                                 (picInfo.BasePhotoInfo.Height * 2.54).ToString("0.00") + @")\" +
                                                 DateTime.Now.ToString(),
                                                rcFont,
                                                SpecialEffectsTextStyle.Normal,
                                                SpecialEffectsTextAlignmentFlags.HorizontalCenter | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                                0, /* horizontal  shadow position */
                                                0, /* vertical shadow position */
                                                FontColor,/* text color, blue */
                                                Color.White,/* shadow color, black */
                                                Color.White, /* border color, white */
                                                textFont,
                                                null);

                            g.Dispose();
                            ColorImgBlock.Dispose();//释放色块的资源
                            #endregion

                            UPTLab("向中间图片mdiImageTemp图贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            Rectangle barCodeRec, picRec;

                            if (picInfo.barCodeStatus == SmallERP.COM.Status.PhotoBarCodeStatus.RightOrLeft)//条码在左\右边
                            {
                                RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                rcBarcode.Angle = 90 * 100;
                                rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                rcBarcode.Flags = RotateCommandFlags.Resize;
                                rcBarcode.Run(barcodeImageTemp);

                                //barCodeRec = new Rectangle(0, 0, BARCODEHEIDHT, barcodeImageTemp.Height);
                                //picRec = new Rectangle(BARCODEHEIDHT, 0, smallPicImage.Width, smallPicImage.Height);

                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                barCodeRec = new Rectangle(smallPicImage.Width, 0, BARCODEHEIDHT, barcodeImageTemp.Height);

                            }
                            else  //0:条码放在下面
                            {
                                //barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, BARCODEHEIDHT);
                                //picRec = new Rectangle(0, BARCODEHEIDHT, smallPicImage.Width, smallPicImage.Height);

                                picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, BARCODEHEIDHT);
                            }

                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            cfcBarcode.SourcePoint = Point.Empty;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.DestinationImage = midImageTmp;


                            //if (board.AddSharpen <= 0)//如果大板没有设置锐化就只对条码进行锐化
                            //{
                            //    UPTLab("对条码进行锐化");
                            //    SharpenCommand command = new SharpenCommand();
                            //    command.Sharpness = 950;
                            //    command.Run(barcodeImageTemp);
                            //}

                            UPTLab("贴条码");
                            //贴条码
                            cfcBarcode.DestinationRectangle = barCodeRec;
                            cfcBarcode.Run(barcodeImageTemp);

                            UPTLab("贴图片");
                            //贴图片
                            cfcBarcode.DestinationRectangle = picRec;
                            cfcBarcode.Run(smallPicImage);

                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                            #endregion

                        }
                        else//无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                                                               0,
                                                                               0,
                                                                               smallPicImage.Width,
                                                                               smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }
                        #endregion

                        UPTLab("给中间图画边框");
                        #region //给中间图画边框
                        Graphics g2 = null;
                        try
                        {
                            SpecialEffectsProcessor processor2 = new SpecialEffectsProcessor();
                            g2 = midImageTmp.CreateGdiPlusGraphics().Graphics;

                            Rectangle rcShape2 = new Rectangle(0, 0, midImageTmp.ImageWidth, midImageTmp.ImageHeight);


                            processor2.Draw3dShape(g2,
                                                     SpecialEffectsShape.Rectangle, /* star shape */
                                                     rcShape2,  /* destination rectangle */
                                                     Color.Black, /* background color, blue */
                                                     null, /* use this to place an image in the background */
                                                     rcShape2, /* display background rectangle */
                                                     SpecialEffectsBackStyle.TranslucentTiledImage, /* style flags for 3D shape */
                                                     Color.Black, /* foreground color, red */
                                                     SpecialEffectsFillStyle.Transparent, /* foreground style */
                                                     Color.Black, /* border color, red */
                                                     SpecialEffectsBorderStyle.Solid, /* border style */
                                                     1, /* border width */
                                                     Color.Black, /* inner band highlight color, white */
                                                     Color.Black, /* inner band shadow color */
                                                     SpecialEffectsInnerStyle.None, /* inner band style */
                                                     0, /* inner band width */
                                                     Color.Black, /* outer band highlight color, RED */
                                                     Color.Black, /* outer band shadow color */
                                                     SpecialEffectsOuterStyle.None,/* outer band style */
                                                     1, /* outer band width */
                                                     0, /* horizontal shadow position */
                                                     0, /* vertical shadow position */
                                                     Color.Black, /* shadow color, black */
                                                     null);    /* no region handle */

                        }
                        catch (Exception Boardex)//如果添加边框出错就不添加
                        {
                            WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.BasePhotoInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                        }
                        finally
                        {
                            if (g2 != null)
                            {
                                g2.Dispose();
                            }
                        }

                        #endregion

                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }


                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                                                                        pointX,//在大图上的坐标
                                                                        pointY,
                                                                        midImageTmp.Width,//长和宽
                                                                        midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (DateTransfer.IsAutoCut)//自动裁切模式
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();

                            photoP.X = pointX;
                            photoP.Y = pointY;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;
                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.PhotoS.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.BasePhotoInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.BasePhotoInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;

                int qipanHeight = 30;
                if (DateTransfer.IsAutoCut)//自动裁切模式要替换最终destImage
                {
                    UPTLab("创建自动裁切信息");
                    ///创建大板的条码信息
                    //RasterImage destTempImage = destImage;//先将名称替换掉
                    RasterImage boardPointInfoImage = new RasterImage(
                                                        RasterMemoryFlags.Conventional,
                                                        qipanHeight,
                                                        destImage.Height,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//条码信息色块中间白板图

                    RasterImage destTempImage = new RasterImage(RasterMemoryFlags.Conventional,
                                                        destImage.Width,
                                                        destImage.Height + qipanHeight,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);//);
                    ///填充颜色
                    FillCommand fcommandW = new FillCommand();
                    fcommandW.Color = new RasterColor(255, 255, 255);
                    fcommandW.Run(destTempImage);
                    fcommandW.Run(boardPointInfoImage);
                    destTempImage.XResolution = destImage.XResolution;

                    destTempImage.YResolution = destImage.YResolution;
                    //条码文字信息
                    //Graphics g = barcodeImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                    //SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    int recCurrX = XExcursion, recCurrY = 0;





                    //打定位色块第一组
                    #region///棋盘定位
                    RasterImage ColorImgBlockWhite = CreateColorBlock(Color.Red.R, Color.Red.G, Color.Red.B);
                    RasterImage ColorImgBlockBlack = CreateColorBlock(Color.Black.R, Color.Black.G, Color.Black.B);



                    UPTLab("粘贴色块");
                    //粘贴色块
                    //第一组色块中心距离原点30+偏移
                    int currRecy = 0;
                    for (int icolor = 0; icolor < 51; icolor++)
                    {
                        if (icolor % 2 == 0)
                        {
                            CombineFastCommand cfcColor11 = new CombineFastCommand();
                            cfcColor11.DestinationRectangle = new Rectangle(
                             currRecy,
                             5,
                             10,
                             10);

                            cfcColor11.SourcePoint = Point.Empty;
                            cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcColor11.DestinationImage = boardPointInfoImage;
                            cfcColor11.Run(ColorImgBlockBlack);
                        }
                        else
                        {
                            CombineFastCommand cfcColor11 = new CombineFastCommand();
                            cfcColor11.DestinationRectangle = new Rectangle(
                             currRecy,
                             15,
                             10,
                             10);

                            cfcColor11.SourcePoint = Point.Empty;
                            cfcColor11.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcColor11.DestinationImage = boardPointInfoImage;
                            cfcColor11.Run(ColorImgBlockWhite);
                        }
                        currRecy += 10;
                    }




                    #endregion
                    #region///文字 条码信息
                    //条码文字
                    SizeF sizeF = gFont.MeasureString("*" + board.BoardBaseInfo.BoardId.ToString() + "*", textBarFont3o9);

                    //打条码
                    Rectangle rcBarcode = new Rectangle(800, 0, 525, 30);//在200打75宽 50高的条码

                    Graphics gb = boardPointInfoImage.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字

                    SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                    processor.Draw3dText(gb,
                                       "*" + board.BoardBaseInfo.BoardId + "*",
                                         rcBarcode,
                                         SpecialEffectsTextStyle.Normal,
                                         SpecialEffectsTextAlignmentFlags.HorizontalCenter | SpecialEffectsTextAlignmentFlags.VerticalCenter,
                                         0, /* horizontal  shadow position */
                                         0, /* vertical shadow position */
                                         Color.Black, /* text color, blue */
                                         Color.White,/* shadow color, black */
                                         Color.White, /* border color, white */
                                         textBarFont3o9,
                                         null);

                    //粘贴色块

                    //打印文字及其区域

                    Rectangle rcFont = new Rectangle(1500, 0, board.BoardBaseInfo.Length - 800, 30);

                    string barStr = board.BoardBaseInfo.BoardId.ToString();


                    processor.Draw3dText(gb,
                                        barStr,
                                        rcFont,
                                        SpecialEffectsTextStyle.Normal,
                                        SpecialEffectsTextAlignmentFlags.Left | SpecialEffectsTextAlignmentFlags.Top,
                                        0, /* horizontal  shadow position */
                                        0, /* vertical shadow position */
                                        Color.Black,/* text color, blue */
                                        Color.White,/* shadow color, black */
                                        Color.White, /* border color, white */
                                        textFont,
                                        null);

                    gb.Dispose();
                    #endregion

                    CombineFastCommand cfctop = new CombineFastCommand();
                    cfctop.DestinationRectangle = new Rectangle(XExcursion + 490, 0, boardPointInfoImage.Width, boardPointInfoImage.Height);
                    cfctop.SourcePoint = Point.Empty;
                    cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(boardPointInfoImage);
                    cfctop.DestinationRectangle = new Rectangle(XExcursion, qipanHeight, destImage.Width, destImage.Height);
                    cfctop.DestinationImage = destTempImage;
                    cfctop.Run(destImage);
                    destImage = destTempImage;//重新赋值

                    //写入文件
                    StringBuilder sbWriter = new StringBuilder();
                    foreach (PhotoPoint pp in listPhotoInfoForCut)
                    {
                        string mmX = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + MerginMMCen)).ToString("0.0");
                        string mmy = (((double)pp.Y / board.BoardBaseInfo.DPI * 2.54 * 100 + qipanHeight)).ToString("0.0");
                        string mmWidth = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMCen * 10)).ToString("0");
                        string mmheight = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - MerginMMCen * 10)).ToString("0");
                        string dxfFlag = "DXF";
                        string strWriter = "";
                        if (pp.DXFContent == null)
                        {
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                        }
                        else
                        {
                            string angleStr = pp.Angle.ToString();
                            string wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                            string hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                            string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", ";");
                            strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                        hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                        }
                        sbWriter.AppendLine(strWriter);

                    }

                    WrtieText(sbWriter, _curCutFileFullPath);
                }
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;

                if (board.AddSharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    SharpenCommand command = new SharpenCommand();
                    command.Sharpness = board.AddSharpen;
                    command.Run(destImage);
                }

                UPTLab("正在保存大图...");
                bool isNeedAddIcc = false;
                if (!string.IsNullOrEmpty(board.IccPath))
                {
                    if (board.IccPath.EndsWith(".icc", true, null) || board.IccPath.EndsWith(".icm", true, null))
                    {
                        if (File.Exists(board.IccPath))
                        {
                            isNeedAddIcc = true;//只有当ICCPATH不为空字符串，则是以。ICC、ICM结尾的，且文件存在的才加ICC
                        }
                    }

                }

                if (isNeedAddIcc)//需要加载ICC
                {
                    if (DateTransfer.AddIccByType == 0)//需要用PS加载ICC
                    {
                        //先保存到本地,等加载好ICC时存到网络路径                  
                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, strTempPath, RasterImageFormat.Tif, 24);
                                break;
                        }

                        //再调用PS加载ICC
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName = board.IccPath.Substring(board.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                            }
                            catch { }
                            string strPicFormat = "JPEG";
                            //string strInputIcc = "ColorMatch RGB";
                            string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            if (board.IsTransverse)//竖向的就转90
                                intRatate = -90;
                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //string strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);


                            string strResult = psApp.AddICC(iccName, strTempPath, destFileName);


                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件错误" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                            }
                            catch { }
                        }
                    }
                    else//用LEADTOOLS加载ICC
                    {
                        //处理旋转的问题
                        if (board.IsTransverse)//竖向的就转90
                        {
                            UPTLab("正在竖向旋转90度...");
                            if (destImage.Width >= 18898 || destImage.Height >= 18898)//大于这个尺寸就用PS进行旋转
                            {
                                try
                                {
                                    File.Delete(Application.StartupPath + "\\tem.jpg");
                                }
                                catch { }

                                codecs.Save(destImage, Application.StartupPath + "\\temBig.jpg", RasterImageFormat.Jpeg, 24);

                                //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                                //myClass.DoRotate(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", true, 90);
                       

                            psApp.RotatePic(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", 90);

                                destImage = codecs.Load(Application.StartupPath + "\\tem.jpg");
                                File.Delete(Application.StartupPath + "\\temBig.jpg");
                            }
                            else
                            {
                                RotateCommand rc = new RotateCommand();
                                rc.Angle = 90 * 100;
                                rc.FillColor = new RasterColor(255, 255, 255);
                                rc.Flags = RotateCommandFlags.Resize;
                                rc.Run(destImage);
                            }
                        }

                        switch (PicFormat)
                        {
                            case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                                break;
                            case 1:
                                codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                                break;
                        }

                        try
                        {
                            IccProfileExtended iccProfile = new IccProfileExtended(board.IccPath);
                            iccProfile.WriteToImage(destFileName, destImage.PageCount);
                        }
                        catch (Exception ef)
                        {
                            UPTLab("加载ICC文件错误:" + ef.Message);
                            throw new Exception("加载ICC文件错误" + ef.Message);
                        }
                    }
                }
                else//不需要加载ICC，则直接保存
                {

                    //处理旋转的问题
                    if (board.IsTransverse)//竖向的就转90
                    {
                        UPTLab("正在竖向旋转90度...");
                        if (destImage.Width >= 18898 || destImage.Height >= 18898)//大于这个尺寸就用PS进行旋转
                        {
                            try
                            {
                                File.Delete(Application.StartupPath + "\\tem.jpg");
                            }
                            catch { }

                            codecs.Save(destImage, Application.StartupPath + "\\temBig.jpg", RasterImageFormat.Jpeg, 24);

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            //myClass.DoRotate(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", true, 90);

                            psApp.RotatePic(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", 90);

                            destImage = codecs.Load(Application.StartupPath + "\\tem.jpg");
                            File.Delete(Application.StartupPath + "\\temBig.jpg");
                        }
                        else
                        {
                            RotateCommand rc = new RotateCommand();
                            rc.Angle = 90 * 100;
                            rc.FillColor = new RasterColor(255, 255, 255);
                            rc.Flags = RotateCommandFlags.Resize;
                            rc.Run(destImage);
                        }
                    }

                    switch (PicFormat)
                    {
                        case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }
                }

                #region //写入ICC文件


                #endregion


                destImage.Dispose();
                RasterCodecs.Shutdown();

                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                board.BoardBaseInfo.PicPath = destFileName;
                _mainBLL.MakeBigPicSusscess(board);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString() + "张");


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int)SmallERP.COM.Status.EnumBoardStatus.Error, errText);
            }
            finally
            {
                errText = "";
            }
        }
        //#endregion
        private RasterImage CreateColorBlock(int R, int G, int B)//根据颜色创建色块得到相应的色块
        {
            RasterColor curColor = new RasterColor(R, G, B);

            RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    50,
                    30,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

            FillCommand fcommand = new FillCommand();
            fcommand.Color = curColor;
            fcommand.Run(destImage);

            return destImage;
        }

        void SetErrorMsg(string errMsg)
        {
            UPTLab(errMsg);
            UPTPgro(1, 0);//进度条
            //"与服务器连接异常，请检查与服务器的网络连接"
            UPTListView(0, errMsg, DateTime.Now, 0);
        }

        int whichIcon = 1;
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Properties.Resources));
        private void timerNotifyIcon_Tick(object sender, EventArgs e)
        {
            //this.timerNotifyIcon.Enabled = false;
            //if (timerFlag == false)
            //{
            //    if (whichIcon == 1)
            //    {
            //        this.notifyIcon1.Icon = (System.Drawing.Icon)(resources.GetObject("2"));
            //        whichIcon = 2;
            //    }
            //    else
            //    {
            //        if (whichIcon == 2)
            //        {
            //            this.notifyIcon1.Icon = (System.Drawing.Icon)((resources.GetObject("1")));
            //            whichIcon = 1;
            //        }
            //    }
            //}
            //else
            //{
            //    this.notifyIcon1.Icon = (System.Drawing.Icon)((resources.GetObject("1")));
            //    whichIcon = 1;
            //}
            //this.timerNotifyIcon.Enabled = true;
        }



        #region help methods
        //设置窗体的大小尺寸
        private void SetSize()
        {
            if (_isMore == true)
            {
                this.Width = 546;
                this.Height = 437;
            }
            else
            {
                this.Width = 546;
                this.Height = 140;
            }
        }
        ////设置窗体的位置
        //private void SetLocation()
        //{
        //    Rectangle rect = Screen.PrimaryScreen.WorkingArea;
        //    this.Location = new Point(rect.Width - this.Width, rect.Height - this.Height);
        //}
        private void SetTimer()
        {
            this.timer1.Enabled = true;
            this.timer1.Interval = 3000;

            this.timerNotifyIcon.Enabled = true;
            this.timerNotifyIcon.Interval = 800;
        }

        private Hashtable ColorList = new Hashtable();
        private const int COLORSETUP = 10;
        private int colorIndex = 1;
        private int MinOrderProductId = 0;//放在LIST中最小的那个ORDERPRODUCTID，当hashtableLIST数量达到20个时就删除最小的那个

        //RasterColor Color1 = new RasterColor(255, 255, 255);
        //RasterColor Color2 = new RasterColor(0, 255, 0);
        //RasterColor Color3 = new RasterColor(0, 255, 255);
        //RasterColor Color4 = new RasterColor(255, 0, 255);
        //RasterColor Color5 = new RasterColor(255, 0, 0);
        //RasterColor Color6 = new RasterColor(255, 255, 0);
        //RasterColor Color7 = new RasterColor(0, 0, 255);

        //RasterColor Color8 = new RasterColor(0, 127, 0);
        //RasterColor Color9 = new RasterColor(0, 127, 127);
        //RasterColor Color10 = new RasterColor(127, 0, 127);
        //RasterColor Color11 = new RasterColor(127, 0, 0);
        //RasterColor Color12 = new RasterColor(127, 127, 0);
        //RasterColor Color13 = new RasterColor(0, 0, 127);
        //RasterColor Color14 = new RasterColor(127, 127, 127);
        RasterColor Color1 = new RasterColor(0, 0, 0);
        RasterColor Color2 = new RasterColor(150, 150, 150);
        RasterColor Color3 = new RasterColor(130, 0, 20);
        RasterColor Color4 = new RasterColor(242, 24, 38);
        RasterColor Color5 = new RasterColor(255, 242, 5);
        RasterColor Color6 = new RasterColor(28, 179, 79);
        RasterColor Color7 = new RasterColor(0, 163, 231);

        RasterColor Color8 = new RasterColor(63, 70, 209);
        RasterColor Color9 = new RasterColor(255, 51, 255);
        RasterColor Color10 = new RasterColor(255, 255, 255);
        RasterColor Color11 = new RasterColor(200, 200, 200);
        RasterColor Color12 = new RasterColor(184, 127, 84);
        RasterColor Color13 = new RasterColor(254, 170, 202);
        RasterColor Color14 = new RasterColor(254, 200, 0);
        RasterColor Color15 = new RasterColor(240, 228, 173);
        RasterColor Color16 = new RasterColor(177, 231, 30);
        RasterColor Color17 = new RasterColor(154, 217, 233);
        RasterColor Color18 = new RasterColor(111, 147, 191);
        RasterColor Color19 = new RasterColor(202, 189, 243);
        RasterColor Color20 = new RasterColor(175, 0, 86);
        RasterColor Color21 = new RasterColor(79, 81, 81);

        RasterColor Color22 = new RasterColor(0, 127, 0);
        RasterColor Color23 = new RasterColor(0, 255, 0);
        RasterColor Color24 = new RasterColor(255, 0, 127);
        RasterColor Color25 = new RasterColor(160, 71, 196);
        RasterColor Color26 = new RasterColor(128, 128, 0);
        RasterColor Color27 = new RasterColor(0, 64, 127);
        RasterColor Color28 = new RasterColor(127, 254, 254);
        RasterColor Color29 = new RasterColor(128, 0, 128);
        RasterColor Color30 = new RasterColor(255, 0, 255);

        private RasterImage GetColorBlock(int orderProductId)//根据产品得到相应的色块
        {
            if (orderProductId < MinOrderProductId)
            {
                MinOrderProductId = orderProductId;
            }
            RasterColor curColor;
            if (ColorList.ContainsKey(orderProductId))
            {
                curColor = (RasterColor)ColorList[orderProductId];
            }
            else
            {

                if (colorIndex >= 14)
                {
                    ColorList.Remove(MinOrderProductId);
                    colorIndex = 1;
                    curColor = Color1;
                }
                else
                {
                    #region 设定颜色
                    switch (colorIndex)
                    {
                        case 2: curColor = Color2;
                            break;
                        case 3: curColor = Color3;
                            break;
                        case 4: curColor = Color4;
                            break;
                        case 5: curColor = Color5;
                            break;
                        case 6: curColor = Color6;
                            break;
                        case 7: curColor = Color7;
                            break;
                        case 8: curColor = Color8;
                            break;
                        case 9: curColor = Color9;
                            break;
                        case 10: curColor = Color10;
                            break;
                        case 11: curColor = Color11;
                            break;
                        case 12: curColor = Color12;
                            break;
                        case 13: curColor = Color13;
                            break;
                        case 14: curColor = Color14;
                            break;
                        default: curColor = Color1;
                            break;
                    }
                    #endregion
                    colorIndex++;
                }

                ColorList.Add(orderProductId, curColor);
            }

            RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    COLORBLOCKWIDTH,
                    BARCODEHEIDHT,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

            FillCommand fcommand = new FillCommand();
            fcommand.Color = curColor;
            fcommand.Run(destImage);

            return destImage;
        }
        private RasterImage GetColorBlockT(int orderProductId)//根据产品得到相应的色块
        {
            RasterImage destImage = new RasterImage(
                      RasterMemoryFlags.Conventional,
                      COLORBLOCKWIDTH,
                      BARCODEHEIDHT,
                      24,
                      RasterByteOrder.Bgr,
                      RasterViewPerspective.BottomLeft,
                      null,
                      IntPtr.Zero,
                      0);

            FillCommand fcommand = new FillCommand();
            fcommand.Color = new RasterColor(255, 255, 255);
            fcommand.Run(destImage);

            int HNum = orderProductId / 100 % 100;
            int TNum = orderProductId / 10 % 10;
            int SNum = orderProductId % 10;


            RasterImage HNumImage = new RasterImage(
                      RasterMemoryFlags.Conventional,
                      COLORBLOCKWIDTH / 3,
                      BARCODEHEIDHT,
                      24,
                      RasterByteOrder.Bgr,
                      RasterViewPerspective.BottomLeft,
                      null,
                      IntPtr.Zero,
                      0);

            fcommand.Color = GetColor(HNum);
            fcommand.Run(HNumImage);

            RasterImage TNumImage = new RasterImage(
                      RasterMemoryFlags.Conventional,
                      COLORBLOCKWIDTH / 3,
                      BARCODEHEIDHT,
                      24,
                      RasterByteOrder.Bgr,
                      RasterViewPerspective.BottomLeft,
                      null,
                      IntPtr.Zero,
                      0);

            fcommand.Color = GetColor(TNum); ;
            fcommand.Run(TNumImage);

            RasterImage SNumImage = new RasterImage(
                     RasterMemoryFlags.Conventional,
                     COLORBLOCKWIDTH / 3,
                     BARCODEHEIDHT,
                     24,
                     RasterByteOrder.Bgr,
                     RasterViewPerspective.BottomLeft,
                     null,
                     IntPtr.Zero,
                     0);

            fcommand.Color = GetColor(SNum); ;
            fcommand.Run(SNumImage);

            CombineFastCommand cfctop = new CombineFastCommand();
            cfctop.DestinationRectangle = new Rectangle(0, 0, COLORBLOCKWIDTH / 3, BARCODEHEIDHT);
            cfctop.SourcePoint = Point.Empty;
            cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            cfctop.DestinationImage = destImage;
            cfctop.Run(HNumImage);

            cfctop.DestinationRectangle = new Rectangle(COLORBLOCKWIDTH / 3, 0, COLORBLOCKWIDTH / 3, BARCODEHEIDHT);

            cfctop.DestinationImage = destImage;
            cfctop.Run(TNumImage);

            cfctop.DestinationRectangle = new Rectangle(2 * COLORBLOCKWIDTH / 3, 0, COLORBLOCKWIDTH / 3, BARCODEHEIDHT);

            cfctop.DestinationImage = destImage;
            cfctop.Run(SNumImage);




            return destImage;
        }
        private RasterImage GetColorBlock2(int orderProductId)//根据产品得到相应的色块
        {
            RasterImage destImage = new RasterImage(
                      RasterMemoryFlags.Conventional,
                      COLORBLOCKWIDTH,
                      BARCODEHEIDHT,
                      24,
                      RasterByteOrder.Bgr,
                      RasterViewPerspective.BottomLeft,
                      null,
                      IntPtr.Zero,
                      0);

            FillCommand fcommand = new FillCommand();
            fcommand.Color = new RasterColor(255, 255, 255);
            fcommand.Run(destImage);

            //int HNum = orderProductId / 100 % 100;
            int TNum = orderProductId / 10 % 10;
            int SNum = orderProductId % 10;


            //RasterImage HNumImage = new RasterImage(
            //          RasterMemoryFlags.Conventional,
            //          COLORBLOCKWIDTH / 2,
            //          BARCODEHEIDHT,
            //          24,
            //          RasterByteOrder.Bgr,
            //          RasterViewPerspective.BottomLeft,
            //          null,
            //          IntPtr.Zero,
            //          0);

            //fcommand.Color = GetColor(HNum);
            //fcommand.Run(HNumImage);

            RasterImage TNumImage = new RasterImage(
                      RasterMemoryFlags.Conventional,
                      COLORBLOCKWIDTH / 2,
                      BARCODEHEIDHT,
                      24,
                      RasterByteOrder.Bgr,
                      RasterViewPerspective.BottomLeft,
                      null,
                      IntPtr.Zero,
                      0);

            fcommand.Color = GetColor(TNum); ;
            fcommand.Run(TNumImage);

            RasterImage SNumImage = new RasterImage(
                     RasterMemoryFlags.Conventional,
                     COLORBLOCKWIDTH / 2,
                     BARCODEHEIDHT,
                     24,
                     RasterByteOrder.Bgr,
                     RasterViewPerspective.BottomLeft,
                     null,
                     IntPtr.Zero,
                     0);

            fcommand.Color = GetColor(SNum); ;
            fcommand.Run(SNumImage);

            CombineFastCommand cfctop = new CombineFastCommand();
            cfctop.DestinationRectangle = new Rectangle(0, 0, COLORBLOCKWIDTH / 2, BARCODEHEIDHT);
            cfctop.SourcePoint = Point.Empty;
            cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            cfctop.DestinationImage = destImage;
            cfctop.Run(TNumImage);
            cfctop.DestinationRectangle = new Rectangle(COLORBLOCKWIDTH / 2, 0, COLORBLOCKWIDTH / 2, BARCODEHEIDHT);

            cfctop.DestinationImage = destImage;
            cfctop.Run(SNumImage);




            return destImage;
        }
        private RasterImage GetColorBlockTextBackcolor(int orderProductId)//根据产品得到相应的色块
        {
            RasterImage destImage = new RasterImage(
                      RasterMemoryFlags.Conventional,
                      COLORBLOCKWIDTH,
                      BARCODEHEIDHT,
                      24,
                      RasterByteOrder.Bgr,
                      RasterViewPerspective.BottomLeft,
                      null,
                      IntPtr.Zero,
                      0);

            int colorNum = orderProductId % 30;
            FillCommand fcommand = new FillCommand();

            fcommand.Color = GetColor(colorNum);
            fcommand.Run(destImage);

            ////int HNum = orderProductId / 100 % 100;
            //int TNum = orderProductId / 10 % 10;
            //int SNum = orderProductId % 10;


            ////RasterImage HNumImage = new RasterImage(
            ////          RasterMemoryFlags.Conventional,
            ////          COLORBLOCKWIDTH / 2,
            ////          BARCODEHEIDHT,
            ////          24,
            ////          RasterByteOrder.Bgr,
            ////          RasterViewPerspective.BottomLeft,
            ////          null,
            ////          IntPtr.Zero,
            ////          0);

            ////fcommand.Color = GetColor(HNum);
            ////fcommand.Run(HNumImage);

            //RasterImage TNumImage = new RasterImage(
            //          RasterMemoryFlags.Conventional,
            //          COLORBLOCKWIDTH / 2,
            //          BARCODEHEIDHT,
            //          24,
            //          RasterByteOrder.Bgr,
            //          RasterViewPerspective.BottomLeft,
            //          null,
            //          IntPtr.Zero,
            //          0);

            //fcommand.Color = GetColor(TNum); ;
            //fcommand.Run(TNumImage);

            //RasterImage SNumImage = new RasterImage(
            //         RasterMemoryFlags.Conventional,
            //         COLORBLOCKWIDTH / 2,
            //         BARCODEHEIDHT,
            //         24,
            //         RasterByteOrder.Bgr,
            //         RasterViewPerspective.BottomLeft,
            //         null,
            //         IntPtr.Zero,
            //         0);

            //fcommand.Color = GetColor(SNum); ;
            //fcommand.Run(SNumImage);

            //CombineFastCommand cfctop = new CombineFastCommand();
            //cfctop.DestinationRectangle = new Rectangle(0, 0, COLORBLOCKWIDTH / 2, BARCODEHEIDHT);
            //cfctop.SourcePoint = Point.Empty;
            //cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            //cfctop.DestinationImage = destImage;
            //cfctop.Run(TNumImage);
            //cfctop.DestinationRectangle = new Rectangle(COLORBLOCKWIDTH / 2, 0, COLORBLOCKWIDTH / 2, BARCODEHEIDHT);

            //cfctop.DestinationImage = destImage;
            //cfctop.Run(SNumImage);




            return destImage;
        }
        public RasterColor GetColor(int Num)
        {

            return listColor[Num];
        }
        #endregion

        #region 更新显示、等界面操作
        private void notifyIcon1_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            this.WindowState = FormWindowState.Normal;
        }

        private delegate void DelegateUPTPgro(int total, int value);
        private void UPTPgro(int total, int value)
        {
            if (!this.InvokeRequired)
            {
                this.progressBar1.Maximum = total;
                this.progressBar1.Value = value;
            }
            else
            {
                this.Invoke(new DelegateUPTPgro(UPTPgro), new object[] { total, value });
            }
        }

        private delegate void DelegateUPTLab(string text);
        private void UPTLab(string text)
        {
            if (!this.InvokeRequired)
            {
                this.labelDiaplay.Text = text;
            }
            else
            {
                this.BeginInvoke(new DelegateUPTLab(UPTLab), new object[] { text });
            }
        }
        private delegate void DelegateUPTLabBoardName(string text);
        private void UPTLabBoardName(string text)
        {
            if (!this.InvokeRequired)
            {
                this.toolStripStatusLabel1.Text = "正在渲染:" + text;
            }
            else
            {
                this.BeginInvoke(new DelegateUPTLabBoardName(UPTLabBoardName), new object[] { text });
            }
        }
        private delegate void DelegateUPTLabBoardCount(string text);
        private void UPTLabBoardCount(string text)
        {
            if (!this.InvokeRequired)
            {
                this.toolStripStatusLabel4.Text = "等待渲染:" + text;
            }
            else
            {
                this.BeginInvoke(new DelegateUPTLabBoardName(UPTLabBoardCount), new object[] { text });
            }
        }
        private delegate void DelegateUPTListview(string text);
        private void UPTListview(string text)
        {
            if (!this.InvokeRequired)
            {
                //this.textBox1.Text = this.textBox1.Text + text;
            }
            else
            {
                this.BeginInvoke(new DelegateUPTListview(UPTListview), new object[] { text });
            }
        }

        private delegate void DelegateUPTListView(int baordId, string msg, DateTime time, int status);
        private void UPTListView(int boardId, string msg, DateTime time, int status)
        {
            //if (!this.listView1.InvokeRequired)
            //{
            //    ListViewItem lvi = new ListViewItem(boardId.ToString());
            //    lvi.SubItems.Add(msg);
            //    lvi.SubItems.Add(time.ToString());
            //    switch (status)
            //    {
            //        case 1: lvi.BackColor = Color.Green; break;//normal
            //        default: lvi.BackColor = Color.Red; break;//error
            //    }
            //    listView1.Items.Add(lvi);
            //}
            //else
            //{
            //    this.BeginInvoke(new DelegateUPTListView(UPTListView), new object[] { boardId, msg, time, status });
            //}
        }

        private delegate void DelegateUPlblCount(string msg);
        private void UplblCount(string msg)
        {
            if (!this.InvokeRequired)
            {
                this.toolStripStatusLabel3.Text = "渲染计数:" + msg;
            }
            else
            {
                this.BeginInvoke(new DelegateUPlblCount(UplblCount), new object[] { msg });
            }
        }
        private delegate void DelegateUPTLabBoardErrorCount(string text);
        private void UPTLabBoardErrorCount(string text)
        {
            if (!this.InvokeRequired)
            {
                this.toolStripStatusLabeleErrorNum.Text = "错误计数:" + text;
            }
            else
            {
                this.BeginInvoke(new DelegateUPTLabBoardErrorCount(UPTLabBoardErrorCount), new object[] { text });
            }
        }
        private delegate void DelegateGridViewError();
        private void UPTLabBoardErrorList()
        {
            if (!this.InvokeRequired)
            {

                List<BoardModel> list = _mainBLL.GetErrorList();
                if (list.Count == 0)
                {
                    this.Size = new Size(MainFormWidth, MainFormSamllHeight);
                }
                else
                {
                    this.Size = new Size(MainFormWidth, MainFormBigHeight);
                }
                gridControlErrorList.DataSource = list;
                this.toolStripStatusLabeleErrorNum.Text = "错误计数:" + list.Count;
            }
            else
            {
                this.BeginInvoke(new DelegateGridViewError(UPTLabBoardErrorList));
            }
        }
        //private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        //{
        //    this.Visible = false;
        //    e.Cancel = true;
        //    //notifyIcon1.Visible = false;
        //}

        private void 显示主界面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                this.Visible = false;
            }
            else
            {
                this.Visible = true;
            }

        }

        //private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    this.Close();
        //    Application.ExitThread();
        //}

        //private void cmbPicType_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    if (this.cmbPicType.SelectedIndex != 0)
        //        PicFormat = this.cmbPicType.SelectedIndex - 1;
        //}

        private void button1_Click(object sender, EventArgs e)
        {
            _isMore = Reverse(_isMore);

            SetSize();
            SetLocation();
        }

        private bool Reverse(bool value)
        {
            //if (value == true)
            //{
            //    this.btnMore.Text = "详细信息";
            //}
            //else
            //{
            //    this.btnMore.Text = "返回";
            //}
            return !value;
        }

        private void chkIsStart_CheckedChanged(object sender, EventArgs e)//设置开机自动启动
        {
            string exeFileName = Application.ExecutablePath;
            RegistryKey ikey = Registry.LocalMachine;
            try
            {
                if (!File.Exists(Application.StartupPath + @"/Restart.xml"))
                {
                    File.Create(Application.StartupPath + @"/Restart.xml");

                }
                this._xmlOp.Open(Application.StartupPath + @"/Restart.xml");
            }
            catch (FileNotFoundException ex)
            {
                MessageBox.Show("未找到系统相关的关件，请重新安装软件！");
                return;
            }


            ////RegistryKey Run = ikey.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

            ////if (this.chkIsStart.Checked)
            ////{
            ////    Run.SetValue("渲染大图片", exeFileName);
            ////    this._xmlOp.UpdateNodeInnerText("Restart", "Yes");
            ////    this._xmlOp.UpdateNodeInnerText("PrintName", this._printName);
            ////}
            ////else
            ////{
            ////    Run.DeleteValue("渲染大图片");
            ////    this._xmlOp.UpdateNodeInnerText("Restart", "No");
            ////}

            //this._xmlOp.Save();
            //Run.Close();

            //ikey.Close();
        }

        #endregion

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //FrmSetting frmSet = new FrmSetting();
            //frmSet.ShowDialog();

            SetFontInfo();

        }

        /// <summary>
        /// 设置条码的字体属性
        /// </summary>
        void SetFontInfo()
        {
            //if (DateTransfer.TextFontSize < 0)
            //{
            //    FontSize =8;
            //}
            ////FontIsBold = Properties.Settings.Default.BarCodeFontIsBold;

            ////重新加截相关的配置
            //if (FontIsBold)
            //{
            //    textFont = new Font("宋体", FontSize, FontStyle.Bold);//文字的字体
            //}
            //else
            //{
            //    textFont = new Font("宋体", FontSize);
            //}
            ////this.Text = GetHeadTxt();
            //groupBox2.Text = GetHeadTxt();
        }
        public static bool WrtieText(StringBuilder sText, string sFile)
        {
            StreamWriter sw = null;
            try
            {
                string filePath = sFile;
                if (File.Exists(filePath))
                {
                    sw = File.AppendText(filePath);

                    sw.WriteLine(sText);
                }
                else
                {
                    sw = File.CreateText(sFile);
                    sw.WriteLine(sText);
                }
                //sw.Close();
                return true;
            }
            catch (Exception e)
            {
                string a = e.ToString();
                return false;
            }
            finally
            {
                sw.Close();
            }
        }
        public static bool WrtieTextEn(StringBuilder sText, string sFile)
        {
            StreamWriter sw = new StreamWriter(sFile, false, Encoding.Default);
            try
            {
                string filePath = sFile;
                if (File.Exists(filePath))
                {
                    //sw = File.AppendAllText(sFile, sText.ToString(), Encoding.ASCII) ;

                    sw.WriteLine(sText);
                }
                else
                {
                    //sw = File.CreateText(sFile);
                    sw.WriteLine(sText);
                }
                //sw.Close();
                return true;
            }
            catch (Exception e)
            {
                string a = e.ToString();
                return false;
            }
            finally
            {
                sw.Close();
            }
        }
        private void EncryptionAndSave(int inBoardid, StringBuilder sText)
        {
            //UrlSecurity.ClassSecurityClass ucc = new UrlSecurity.ClassSecurityClass();
            //string endStr = ucc.Security(sText.ToString());
            _mainBLL.UpdateBoardPoint(inBoardid, sText.ToString());

        }
        //SmallERP.PaperManange.FrmMain frmPm;
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //frmPm = (SmallERP.PaperManange.FrmMain)Assembly.Load("SmallERP.PaperManange").CreateInstance("SmallERP.PaperManange.FrmMain");
            //frmPm.ShowDialog();
        }
        bool _isrun = false;
        private void timerUDP_Tick(object sender, EventArgs e)
        {
            if (!_isrun)
            {
                try
                {
                    backgroundWorkerUDP.RunWorkerAsync();
                }
                catch
                {
                    _isrun = false;
                }
            }
        }

        private void backgroundWorkerUDP_DoWork(object sender, DoWorkEventArgs e)
        {

            _isrun = true;
            UDPMessage.SendMessage();

        }

        private void backgroundWorkerUDP_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            _isrun = false;
        }

        private void toolStripButtonClear_Click(object sender, EventArgs e)
        {
            setBll.DelHistoryData(DateTransfer.HistoryDataSaveDays);
            MessageBox.Show("数据清理完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void backgroundWorkerDelOrDirvertFolder_DoWork(object sender, DoWorkEventArgs e)
        {

        }

        private void backgroundWorkerDelOrDirvertFolder_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {

        }

        private void backgroundWorkerDelOrDirvertFolder_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {

        }
        private bool isClearRun = false;
        private void timerClearFolder_Tick(object sender, EventArgs e)
        {
            timerClearFolder.Enabled = false;
            try
            {
                BoardBLL.GetOneBoardToClear();
            }
            catch
            {
                // isClearRun = false;
            }
            finally
            {
                timerClearFolder.Enabled = true;
            }
        }

        private void toolStripMenuItemDelete_Click(object sender, EventArgs e)
        {
            List<int> BoardIDs = new List<int>();
            foreach (int rowid in gridViewErrorList.GetSelectedRows())
            {
                BoardModel model = (BoardModel)gridViewErrorList.GetRow(rowid);
                BoardIDs.Add(model.BoardId);
            }
            _mainBLL.DeleteBoards(BoardIDs);
            UPTLabBoardErrorList();
        }

        private void toolStripMenuItemReProduct_Click(object sender, EventArgs e)
        {
            List<int> BoardIDs = new List<int>();
            foreach (int rowid in gridViewErrorList.GetSelectedRows())
            {
                BoardModel model = (BoardModel)gridViewErrorList.GetRow(rowid);
                BoardIDs.Add(model.BoardId);
            }

            _mainBLL.ReProduct(BoardIDs);
            UPTLabBoardErrorList();
        }




    }
    public class PhotoPoint
    {
        public int X { get; set; }
        public int Y { get; set; }
        public double Width { get; set; }
        public double Height { get; set; }
        public int Angle { get; set; }
        public double DXFWidth { get; set; }
        public double DXFHeigth { get; set; }
        public byte[] DXFContent { get; set; }
        public string DxfPath { get; set; }
        public SmallERP.COM.Status.PhotoBarCodeLocal BarCodeLocal { get; set; }
    }
}
